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

How to Detect Errors of Our ASP.NET MVC Views on Compile Time - 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

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

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.

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

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

STEP 3:

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

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