0

I have 4 MVC5 projects, each targets a business sector and they have different release schedules, they all have common, structure, look and feel. They all live in the same solution (and they can as well live in different solution) and all of them live on the same directory level:

C:\MySolution\Solution.sln
C:\MySolution\MyFirstMVCProj\MyFirsMVCtProj.cproj
...
C:\MySolution\MyFourthMVCProj\MyFourthMVCProj.cproj

I am using SASS and Gulp to compile and generate CSS.

Currently a common SASS/CSS is "copied and pasted" into each project and any change in the _layout is copied and pasted into each project (if the developer remembers!!).

Is there any modern way, within MVC5, of having a common layout and SASS/CSS outside the projects to avoid the problem of duplication (and accordingly human error) or even a better way of managing this error-prone process?

N.B. I am aware of the Areas feature, but it doesn't suit our business model.

2 Answers 2

1

A little late I know but for anyone googling, see this SO answer about sharing files between projects. I do this and store my css/js in a project of type "shared project".

Following the comment to expand on the other article: Basically you store your common files in the shared project and add them to the destination project but instead of adding them as an existing item (like you would a copy) choose 'add as link' from the menu on the 'add' button. This generates a link to the file in the shared project.

This is not enough though, you need the files copied on build so you need to add the following to each csproj file:

  <Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
    <Copy SourceFiles="%(Content.Identity)" 
          DestinationFiles="%(Content.Link)" 
          SkipUnchangedFiles='true' 
          OverwriteReadOnlyFiles='true' 
          Condition="'%(Content.Link)' != ''" />
 </Target>
Sign up to request clarification or add additional context in comments.

1 Comment

Rather than just link to another SO answer, can you summarize the points here? Answers are sometimes modified or removed, so it could be better to have the info here, in addition to the link.
0

You could keep the common SASS library with all shared properties in a separate place and import it with different variables set to your projects.

5 Comments

could you please elaborate given the ASP.NET MVC environment and include a solution for the layout page?
I have never worked with ASP.NET, but I think this is rather a SASS question. So just keep your shared SASS outside of the other projects (with separate versioning?) and import it to your SASS files inside your projects by overwriting the default variables if needed.
You can define a variable inside SASS with $your-color-variable: black !default. Then you could overwrite the variable with $your-color-variable: #123 in your projects. After overwriting the variable you import the shared library with something like @import "../../my-sass-library/shared-library".
Actually, SASS is secondary, the main problem is _layouts of ASP.NET
As I said, I’m not into ASP.NET, but did you try symlinks? Keep _layout in an external folder and just add symlinks in the projects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.