For some unknown reason, setting CodeAnalysisTreatWarningsAsErrors to false made the analyzer more aggressive. The CA1307 warning started to appear in my editor (VSCode with C# Dev Kit) even though CA1307 is not included in the default code analysis level.
Analyzer
Diagnostic ID: CA1307 :
Specify StringComparison for clarity
Analyzer source
SDK: Built-in CA analyzers in .NET 5 SDK or later
Version: SDK 8.0.301
Describe the bug
I want to treat C# compiler warnings as errors, but not code analysis warnings.
For some unknown reason, setting
CodeAnalysisTreatWarningsAsErrors
tofalse
made the analyzer more aggressive. The CA1307 warning started to appear in my editor (VSCode with C# Dev Kit) even though CA1307 is not included in the default code analysis level.Steps To Reproduce
Project:
Program.cs:
Expected behavior
No analyzer warnings should be reported in VSCode.
dotnet build
should succeed without warnings or errors.Actual behavior
CA1307 is reported as a warning in VSCode (but not by
dotnet build
).CA1307 goes away completely when you flip
CodeAnalysisTreatWarningsAsErrors
fromfalse
totrue
.Additional context
CA1307 should only be reported when
AnalysisMode
isAll
.