Compilation errors in Razor Views

Ok, so after a some searching in the documentation of Visual Studio, MSBUILD and some other things; also some other blogs and Stack Overflow. I was able to find a way to be able to compile Razor views, and after compilation Visual Studio populated the Errors list with errors in views.

One thing to keep in mind is, the compilation of views does take a lot more time, then the rest of the solution. While testing this out, our solutions build time was increased from < 30 secs to ca 2.5 minutes. Which almost a 5 times increase in compilation time. So, I figured, I can use this only when it is really needed. Like after a merge. All I have to do is change one boolean in .csproj file with Razor views. First of all you need to add this in the first <PropertyGroup />.

I have it just under <TargetFrameworkVersion /> tag. Then it is good to add a condition, so that you can toggle <MvcBuildViews /> tag, so that under development you don't have to wait for views to compile.

In some cases it is also a good idea to add

just under <OutputPath /> tag.

Leave a Reply