Firstly I created a new folder in my solution where all the shared resources would be stored, and created subfolders under this to order the resources, one for fonts, one for images etc.
Then I created physical folders which matched these solution folders.
Then I copied the physical resources into these folders. These folders were committed to git. This is where the resources would be kept. Then to add the resources into my solution I right clicked on the folder in the Solution Explorer and selected Add => Existing Item. Then I navigated to the new physical files which I had just made and added them here.
This added the resources to the solution. The next step was to reference these shared resources from each project which needed them. To do this I followed almost the same steps as before, create the solution folder in the web application project, then right click => Add => Existing Item and browse to where the resource is located (in the common folder which I created earlier). But this time instead of clicking Add, I clicked on the arrow next to the Add button and selected Add As Link.
This adds a link to the resource rather than making a copy of the resource which is exactly what I wanted. You can tell if the resource is added as a link because it will have a small blue arrow in the corner of the icon which is the link icon.
Now I could build and publish my projects and the resources are included from the common location into each web application.
However there is one downside which is that when debugging the website these shared resources are not there. There is a trick to get this to work which I found on the blog of Matt Perdeck: http://mattperdeck.com/post/Copying-linked-content-files-at-each-build-using-MSBuild.aspx. I added a target to the .csproj file for each project that tells MSBuild to copy the shared resources on build, so that debugging will also work. I added the following code at the end of my .csproj file for each project:
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build"> <Copy SourceFiles="%(Content.Identity)" DestinationFiles="%(Content.Link)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" Condition="'%(Content.Link)' != ''" /> </Target>
It was simple for me with just a few steps to share resources between projects in my solution and adhere to the DRY (Don’t Repeat Yourself) philosophy and hopefully reduce the number of bugs in our project in the future.