Based on my experience developing Asp.Net MVC, Visual Studio has limited support for JavaScript. I suppose there is something you can do to mimic the behavior you want:
-
Create a project to store your JavaScript files, perhaps a Class Library project it doesn’t really matter, as long as it supports Build Events. Put your JavaScript files inside new project.
-
Create a post build step on this project to minimize your JavaScript using an external tool. I use YUI Compressor. Your post build step should contain lines similar to the following:
java -jar $(ProjectDir)Scripts\yuicompressor-2.4.7.jar $(SolutionDir)Scripts\yourJsFile.js -o $(SolutionDir)Scripts\yourJsFile.min.js –charset utf-8
-
Include this new project in your solution. Then for your Asp.Net projects, set up your Active Server Pages such that they reference the JavaScript files, I am using Razor syntax as an example. It might be tricky to specific the correct path though:
@if (@Model.IsDebug) { <script src="https://stackoverflow.com/questions/9540773/@Url.Content("~/Scripts/yourJsFile.js")" type="text/javascript"> </script> } else { <script src="https://stackoverflow.com/questions/9540773/@Url.Content("~/Scripts/yourJsFile.min.js")" type="text/javascript"></script> }
Again it might be tricky to ensure that you can accurately reference the JavaScript files from your Asp.Net project. But I’m sure there is a way to do it. Perhaps you can have your post build step copy the JavaScript files to some common location. If you do this you will also want to mark the post build event on your JavaScript project as “Always Run”, so the JavaScript files are always copied.