1

Hope you are doing great!

I faced a problem with my project where I wanted all analyzers warnings to be errors. I simply can't make all warnings into errors.

To reproduce an issue I created a simple project: https://github.com/hasrthur/DotNetCoreWarningsTest.

.editorconfig has a settings to treat all analyzers violations as errors.

dotnet_analyzer_diagnostic.severity = error

*.csproj file has the same setting set

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <AnalysisMode>AllEnabledByDefault</AnalysisMode>
    <AnalysisLevel>latest</AnalysisLevel>
    <EnableNETAnalyzers>true</EnableNETAnalyzers>
    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
    <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <NoWarn>CA1014,CA1812</NoWarn>
  </PropertyGroup>

</Project>

Program.cs contains redundant using statement

using System; // <- this should trigger error
// See https://aka.ms/new-console-template for more information
Console.WriteLine(42);

Rider shows that line as error.

But when I build a project either via rider or console the build succeeds.

Even if I add

dotnet_diagnostic.IDE0005.severity = error

to .editorconfig it has no effect at build time but when I add

dotnet_diagnostic.IDE0005.severity = none

the warning/error disappears in rider

What am I missing?

hasrthur
  • 1,410
  • 15
  • 31

0 Answers0