【问题标题】:EnforceCodeStyleInBuild true does not fail the build when errors are present存在错误时,EnforceCodeStyleInBuild true 不会使构建失败
【发布时间】:2020-11-16 15:53:18
【问题描述】:

我正在使用 VS 2019 16.9.0 Preview 1.0 并且有一个具有以下 PropertyGroup 的项目

<PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>net5.0</TargetFramework>
  <LangVersion>latest</LangVersion>
  <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
  <EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>

在我的 .editorconfig 中,我创建了以下划线 _ 开头的字段规则。在 Visual Studio 中,我可以看到错误为 IDE1006。但是,这不会导致构建失败。从我读到的设置&lt;EnforceCodeStyleInBuild&gt;true&lt;/EnforceCodeStyleInBuild&gt; 应该会导致构建失败。我在 Visual Studio 和命令行中使用 dotnet build 对此进行了测试。

我怎样才能让这个错误导致构建失败?

【问题讨论】:

  • 你有没有想过在这种情况下如何让构建失败?您从未在下方回复或接受过答案。

标签: visual-studio-2019 csproj .net-5 editorconfig


【解决方案1】:

将 /WarnAsError 标志传递给 dotnet build:

dotnet build /WarnAsError

【讨论】:

    【解决方案2】:

    您必须设置 dotnet_diagnostic.IDE1006.severity = errorwarning 才能使其工作。 CLI 只能识别这种语法。

    在类似主题上查看我的相关@​​987654321@ 之一。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多