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

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

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

One Comment

  1. Грузовые шины February 18, 2016 at 8:37 am

    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 Comment