1

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.

1 Answer 1

1

I've had the same requirement before and this is how I dealt with it:

Move your shared content

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.

Add linked shared files to the solutions

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:

  1. Right click the folder you wish to add the file to
  2. Hover over Add then select Existing Item
  3. Navigate to the file in the Shared project and select the file
  4. Before clicking 'Add`, notice the arrow
  5. Click this, and select Add 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.

Add pre-build events

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:

  1. Right click your project and select Properties
  2. Select Build Events in the menu
  3. In 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)

Sign up to request clarification or add additional context in comments.

2 Comments

@bogdan If you use TeamCity for automatic deployment you'll have to add the build events as well
I use TFS for automatic deployment. But in this case I should add the build events also.

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.