Handling common JavaScript files in Visual Studio 2010
javascript, visual-studio-2010
Solution
In the end, this is how I've achieved it. It may not be to everyone's taste - but worked a treat for me.
Note: In all of our projects, static resources are in a root directory called 'Assets', so for example JavaScript is always in /Assets/js/ and CSS /Assets/css/.
Solution
- In the project that is going to 'import' the common code, I simply add the common .js file 'As Link' within /Assets/js/.
- Go to that new addition's Properties and set 'Copy to Output Directory' to 'Copy if newer'.
- Now I simply edit the project's post-build event command line to the following: xcopy /Y /E "$(TargetDir)\Assets" "$(ProjectDir)\Assets"
When the project builds, it copies the imported files to \bin\Assets\js - the post-build event then takes a copy of those over to the project directory - in time for the site to use them.
Problem
We're beginning work on a couple of fully JavaScript-dependent web apps (our previous apps have been ASP.NET MVC, with JavaScript 'goodness' sprinkled over-the-top). We have a few files that will be shared across the board, and it would be nice to store these files in a Common project, and 'Add As Link' them into individual projects (as would be possible with compiled code). Obviously this doesn't work with something like JavaScript as the file isn't actually 'there' in the correct location. Does anyone have any suggestions on keeping a single version of a shared JavaScript file, for use across multiple projects?