How to check view files for build errors during build (without opening)

By default, Visual Studio checks for build errors in CSHTML files if they are open during creation. I want this to happen when building for closed CSHTML files.

I saw in this post: How to compile cshtml before running or this post

The solution was simple, just install this in the csproj file:

<MvcBuildViews>true</MvcBuildViews> 

Unfortunately, this leads to errors in the cs files that it creates in temporary folders. The cs files are converted html cs files and are not compiled by themselves, so I get a lot of build errors that don't really exist.


My current solution is that I set the MvcBuildViews parameter to false, and then manually open all the CSHTML files in the project before creating it.

Is there a fix for skipping temporary files or a more efficient way than opening all CSHTML files?

+6
source share
1 answer

Is there a fix for skipping temporary files or a more efficient way than opening all CSHTML files?

The only supported method is the project configuration element <MvcBuildViews> . This is MsBuild support, which allows you to work with unattened builds. This is the most efficient way to check for assembly errors in views.

Cs files are converted html cs files

What does it mean? vbhtml or cshtml . There are no views in the .cs extension.

Without adding the correct configuration items (below), you may get some odd errors when cshtml files cshtml converted to .cs (intermediate files) and then compiled.

Unfortunately, this leads to errors in the cs files that it creates in temporary folders.

There are many answers ( 1 2 3 4 ) using <MvcBuildViews> .

Important for understanding MVC projects (actually web projects in general) is that each view is compiled by default in the obj / bin directory of the project. The problem usually arises when IIS and IIS Express try to compile the views again when they already exist. Thus, the fixes listed above change the compilation directory to a directory outside the project.

0
source

Source: https://habr.com/ru/post/970777/


All Articles