如果.cshtml文件中存在剃刀/ C#错误,如何在VS 2013中使构建失败? [重复]

时间:2022-03-18 20:45:47

This question already has an answer here:

这个问题在这里已有答案:

I'm new to asp.net mvc. I see nasty little red underlines on my .cshtml page in some razor code with errors in the error list, but the project still builds. Can I fail the project build somehow if these errors are about?

我是asp.net mvc的新手。我在.cshtml页面上看到一些剃刀代码中有令人讨厌的小红色下划线,错误列表中有错误,但项目仍在构建中。如果出现这些错误,我能以某种方式失败项目构建吗?

As an aside, if I rename a variable in a c# class referred to in a razor page, why doesn't the refactor tool extend its reach to the cshtml file?

顺便说一句,如果我重命名剃刀页面中引用的c#类中的变量,为什么重构工具不能将其范围扩展到cshtml文件?

2 个解决方案

#1


27  

You need to set in your project to compile views during build.

您需要在项目中设置以在构建期间编译视图。

Set in your MVC project:

在MVC项目中设置:

<MvcBuildViews>true</MvcBuildViews>

All you have to do is unload or close the mvc project in Visual Studio, edit the .cspoj file (in VS or notepad or your favourite editor), locate <MvcBuildViews> and change the value to true.

您所要做的就是在Visual Studio中卸载或关闭mvc项目,编辑.cspoj文件(在VS或记事本或您喜欢的编辑器中),找到 并将值更改为true。

#2


4  

It could be smart using the MvcBuildViews setting only for Release builds, assuming your build process uses a Release build before you deploy. This will remove the extra wait to compile the views when you’re developing and debugging, but still keeps a check in place before you deploy. Add the MvcBuildViews node to the PropertyGroup node for Release builds only. It will look something like this:

如果您的构建过程在部署之前使用了版本构建,那么仅使用版本构建的MvcBuildViews设置可能会很聪明。这将消除在开发和调试时编译视图的额外等待,但在部署之前仍会检查到位。将MvcBuildViews节点添加到PropertyGroup节点,仅用于Release版本。它看起来像这样:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    <MvcBuildViews>true</MvcBuildViews>
</PropertyGroup> 

http://blog.falafel.com/get-compile-time-view-errors-in-asp-net-mvc/

http://blog.falafel.com/get-compile-time-view-errors-in-asp-net-mvc/

#1


27  

You need to set in your project to compile views during build.

您需要在项目中设置以在构建期间编译视图。

Set in your MVC project:

在MVC项目中设置:

<MvcBuildViews>true</MvcBuildViews>

All you have to do is unload or close the mvc project in Visual Studio, edit the .cspoj file (in VS or notepad or your favourite editor), locate <MvcBuildViews> and change the value to true.

您所要做的就是在Visual Studio中卸载或关闭mvc项目,编辑.cspoj文件(在VS或记事本或您喜欢的编辑器中),找到 并将值更改为true。

#2


4  

It could be smart using the MvcBuildViews setting only for Release builds, assuming your build process uses a Release build before you deploy. This will remove the extra wait to compile the views when you’re developing and debugging, but still keeps a check in place before you deploy. Add the MvcBuildViews node to the PropertyGroup node for Release builds only. It will look something like this:

如果您的构建过程在部署之前使用了版本构建,那么仅使用版本构建的MvcBuildViews设置可能会很聪明。这将消除在开发和调试时编译视图的额外等待,但在部署之前仍会检查到位。将MvcBuildViews节点添加到PropertyGroup节点,仅用于Release版本。它看起来像这样:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    <MvcBuildViews>true</MvcBuildViews>
</PropertyGroup> 

http://blog.falafel.com/get-compile-time-view-errors-in-asp-net-mvc/

http://blog.falafel.com/get-compile-time-view-errors-in-asp-net-mvc/