Compiling Views in ASP.NET MVC
14 May 2010
asp.net c# compiling mvc visual studio 2010
With ASP.NET MVC re introducing developers to inline scripting there is an increased chance that although the coding in your MVC Controllers may compile correctly, there still may be errors hidden within your MVC Views. These errors will wait to be discovered by the user hitting the View.
In order to enable the compiling of MVC Views, and avoid this issue, you need to manually update the xml content of the Visual Studio .csproj file. This can be done by right clicking on the project in the "Solution Explorer" and selecting "Unload Project". Once the project has been unloaded right click again and select "Edit".
Find the "MvcBuildViews" property tag for the project, which is set to false by default. Simply change the value to true in order to enable MVC View compiling.
Now when you reload the project and build the solution the MVC Views will be compiled, hence alerting you to any inline scripting errors they may contain.
Alternatively, you can just enable MVC View compiling for specific solution configurations. As compiling adds a significant overhead to the build process you may prefer to just enable for release builds. In order to do this find the "PropertyGroup" tag relating to the release build and add an additional "MvcBuildViews" property tag.