12

I'm using VS 2019 16.9.0 Preview 1.0 and have a project with the following PropertyGroup

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

In my .editorconfig I created rules for fields to start with an underscore _. in Visual Studio I can see the error as IDE1006. However this does not cause the build to fail. From what I have read the setting <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> should cause the build to fail. I tested this in Visual Studio and from the Command Line using dotnet build.

How can I have this error to cause a build failure?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
wertzui
  • 5,148
  • 3
  • 31
  • 51
  • 1
    Did you ever figure out how to make the build fail in that case? You never replied or accepted an answer below. – SuperOli Feb 18 '22 at 18:01

2 Answers2

2

You have to set dotnet_diagnostic.IDE1006.severity = error or warning to get it work. CLI only recognize this syntax.

See one of my related answer on similar topic.

KUTlime
  • 5,889
  • 1
  • 18
  • 29
0

Pass the /WarnAsError flag to dotnet build:

dotnet build /WarnAsError

ngprice
  • 156
  • 2
  • 8