How to find compile-time errors in Razor MVC views?

When I make a change to the model used by several views, but neglecting to update one or more views to reflect the changes, the problem becomes apparent only when I actually view the affected view, thereby starting compilation at runtime.

How can I find such errors during compilation in Visual Studio?

+4
source share
1 answer

By default, MVC views are compiled at runtime. To force them to compile at build time, follow these steps:

  • Edit project file in a text editor
  • Change the line <MvcBuildViews>false</MvcBuildViews> to <MvcBuildViews>true</MvcBuildViews>
  • Save the changes and allow Visual Studio (if executed) to reload the project file when prompted.

The building will take a little longer. However, on my (fast) system with an average project, I hardly notice the difference.

+6
source

All Articles