Monday 12 December 2011

How to force view compilation in an ASP.NET MVC project

When you build an ASP.NET MVC project, the default behaviour is to exclude view files from compilation. To include views unload the project (in Solution Explorer right click the project and select Unload Project) and edit the project file (right click the project node and select Edit <project name>.csproj).  Locate the MvcBuildViews setting and change this to true.  On reloading the project, building will now compile all views.

Note that this will include all view files in the project's Views folder on disk, even if these are not added to the project.