Reputation: 319
I have common asp.net mvc project.
I have there one module that contains handlebars templates, javascript modules and stylesheets. This module is used into different pages and placed somewhere inside div tag.
The new requirement is to use this module into other solution. But I do not want just copy and paste all files related to the module (js, html, css) because it would be hard to maintenance it into different solutions.
So, my question is in what way I should organize this module to be declared only once and to be used into different solutions.
Upvotes: 1
Views: 289
Reputation: 11971
I've had the same requirement before and this is how I dealt with it:
In my solution, I added a new Shared
folder and created a Shared
project. You don't necessarily have to move into a new project, I just did this because the shared project also included shared MVC logic.
It's important to know that this step is optional, it's just that it helps developers in that the files are still in the expected place. Now that you have for example: Project1
, Project2
and Shared
. Now in Project1
(for example), add your files back in individually. But follow these steps:
Add
then select Existing Item
Shared
project and select the fileAdd as Link
The benefit of this is that when you click on the file in your solution explorer within Project2
, it will open the file in Shared
.
In each project using the Shared
files you will need to add Pre Build Events
. Currently, although the project contains a reference to the shared file, it won't actually do anything when you run the project. The solution to this is build events:
Properties
Build Events
in the menuIn the Pre-build event command line
section enter the following:
xcopy /R /E /Y "$(SolutionDir)SharedProject\Scripts" "$(ProjectDir)Scripts"
To explain: this will copy the contents of your scripts directory in your shared project, and add it to (or replace) your current projects scripts directory. You will need to add a line for each folder (e.g. HTML, CSS, etc)
Upvotes: 1