To compile MVC views at build time you can modify the MvcBuildViews option in the project file. To do this you have to manually edit your .proj file and setting MvcBuildViews=”true”. This gives you design time compilation of all your views so you can catch an silly view errors before running the website but the build time will be increased due to the extra compilation time.
However, when I set MvcBuildViews=”true” I immediately get the following build error:
It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS
The issue is caused by multiple web.config files in the obj folder. To fix this issue I added the BaseIntermediateOutputPath element to the .proj file. My .proj file now contains this:
I also had to delete the contents of the existing obj folder.
Everything now builds and I get design time error checking of all the MVC views.
More information about this issue can be found here: