Home > Software engineering >  Visual Studio 2022 - Code Analysis Build errors not failing build
Visual Studio 2022 - Code Analysis Build errors not failing build

Time:05-25

I have code analysis enabled in project and warnings as errors

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
  </PropertyGroup>
  <PropertyGroup>
    <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
  <PropertyGroup>

I've added a .editorConfig and set some rules (e.g. no multiple blank lines).

I see Errors in the Error List in the IDE, and I get red wiggles showing in the code:

VS2021 screenshot

However, the project still builds fine. (I can nuke the bin folder and build, see the errors and it still outputs the files into the bin folder).

Why is it ignoring the errors?

I'd like to make it so that these code analysis errors actually fail the build.

CodePudding user response:

Found a solution

Add this to your .editorconfig:

dotnet_analyzer_diagnostic.category-Style.severity = error
  • Related