CA2007 severity as error not applying
Charles-Gagnon opened this issue · comments
Analyzer
Diagnostic ID: CA2007
Analyzer source
SDK: Built-in CA analyzers in .NET 5 SDK or later
Version: 6.0.419
Describe the bug
Setting CA2007 severity to error
in my .editorconfig doesn't seem to be picked up by Visual Studio/dotnet
dotnet_diagnostic.CA2007.severity = error
I also have the following settings in the project props.
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
Expected behavior
When I build my project with code that fails the check, the build fails and is displayed as an error in Visual Studio.
Actual behavior
It is flagged as a warning and the build completes successfully.
Repro Project
I just tested this and it works for me. Can you try this in an empty solution? Also make sure you don't have multiple .editorconfig
files which might be picked up by the analyzer.
Thanks for checking @CollinAlpert ! I attached a simplified repro project to the original issue, could you check if it still fails the build for you?
Thanks, I can reproduce your issue now. The problem is you have <CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
set. When removed, the error is correctly displayed.
I don't want all warnings to be treated as errors though - just this specific one (and any others I deem important). The issue I found with setting CodeAnalysisTreatWarningsAsErrors to true is that there's no way to leave things as warn (because they're then promoted to errors).
It's true I can set the level to "none" to disable the rule completely - but I'd prefer to be able to keep things as warnings if they're something I want to fix or are good suggestions to think about but not something I want to completely enforce.
Would you say that the behavior of not being able to set the "error" level for this rule is intended behavior? That seems like a bug to me in the first place - especially since I can set the level for some other CA rules such as CA1822 and it works as expected.
My advice would be to set <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
and then use the .editorconfig
file to reduce errors you don't want to warnings.
I get this same issue with .Net 6 - CA2007 shows up as a warning despite being configured in .editorconfig as an error. When upgrading to .Net 8 it's an error as expected (shows up with red squiggles in VS and breaks the build)
Same here, I don't have CodeAnalysisTreatWarningsAsErrors
anywhere in csproj files.
I tried to set:
# CS8785: Generator failed to generate source.
dotnet_diagnostic.CS8785.severity = error
First I tried to set it in .editorconfig file on whole repo level, then next to the project where it happens, next I removed all .editorconfig files above the project, nothing worked.
vs 17.9.6
.NET SDK:
Version: 8.0.204
Commit: c338c7548c
Workload version: 8.0.200-manifests.7d36c14f
.NET SDKs installed:
8.0.201 [C:\Program Files\dotnet\sdk]
8.0.204 [C:\Program Files\dotnet\sdk]
MSBuild version 17.9.8+b34f75857 for .NET