Tag Archives: asp.net

ASP.NET MVC compile-time view checks in Visual Studio 2012

Anyone who has worked with MVC has suffered through runtime view errors.  This is because views don’t get compiled until IIS renders them.  In order to check for successful compilation, you can:

  1. Manually visit every view in the browser (easy but tedious)
  2. Create automated UI tests (harder)
  3. Turn on compile-time view checks (just easy)!

Since I like just easy, I’m going to show you how to turn on compile-time view checks:

  1. Unload the project (right-click on the project in Solution Explorer and select Unload Project
  2. Right-click the project again and select Edit *.csproj
  3. In the PropertyGroup section, add: <MvcBuildViews>true</MvcBuildViews>
  4. Save the csproj file and reload the project
  5. Eat a banana (optional)

Now, when running the build, visual studio will compile all of your views as well, and identify any errors.

Advertisements