Menu

Compile Time Checking for MVC Views

June 26, 2014 - .NET / C#, ASP.NET MVC, Deployment, Geek Bits
Compile Time Checking for MVC Views

One advantage of MVC Razor could also be deemed a disadvantage.  No comile time checking of views.  I personally love the dynamic nature of build the Razor views but you can get caught out occassionally and find yourself navigating to a view that is actually broken and generates an error and crashes the web site.

To help allieviate this problem there is a project level setting that you can use to pre-compile the Razor views which will help highlight issues like this before they hit production.  Yes, yes we should all be picking up issues like this well in advance of production and generally that is true but even the hardiest and more comprehensive set of UI testing can miss things or not be quite as comprehensive as one would imagine.

Anyway, the project setting is called MvcBuildViews and you can add it to a project level property group:

<MvcBuildViews>true</MvcBuildViews>

However, use with caution, this can dramatically increase build times and for any large project really is impractical for using in Debug mode. I only ever add this to Release mode meaning that this will get checked in your build process on it’s way to production, if not staging before that.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

*