Enable Errors of Our ASP.NET MVC Views at Compile Time

In this post, we are going to discuss about how to capture “view” errors at compile time. By default, ASP.NET MVC projects won’t compile the views on the building process of our application. But don’t think Visual studio not handle this. As per below screen shot, it’s showing views error as warning in the Error List window, but we won’t consider the warning while running the application. 

How to Detect Errors of Our ASP.NET MVC Views on Compile Time -error - dotnet-helpers

All things are handling her. But many of us really won’t check this warning, as shown above. What we can do here is a fairly simple action to get this blow up on compile time. Let we discuss details about this.

STEP 1:

Right-click on your project’s  solution explorer and click Unload Project as shown in below image

STEP 2: After project unloaded,

After the project unloaded, right-click the project and choose Edit “Your project name” (. csproj) and MvcBuildViews node from false to true (for handlingthe error in compile time) and save the file.

STEP 3:

Reload the project and build the solution. Now we can see the “0 succeed , 1 failed” in the output window.

One thought on “Enable Errors of Our ASP.NET MVC Views at Compile Time”

  1. Your views will now be built at compile -time and you will get syntax errors from any mistakes in your Razor syntax or breaking changes to your model, and you ll get them long before your code makes it in front of users.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.