Adam
Adam

Reputation: 4164

Common Layout and CSS in MVC5 Projects

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.

Upvotes: 0

Views: 460

Answers (2)

Mark Ball
Mark Ball

Reputation: 376

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>

Upvotes: 1

belipe
belipe

Reputation: 41

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.

Upvotes: 0

Related Questions