Analysis mode for code style analyzers does not work in .Net SDK 6
See original GitHub issueDescribe the bug
According to documentation at https://docs.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props we should be able to set analysis mode (e.g. Recommended) for code style analyzers. This does not seem to work at all.
When talking about AnalysisLevel
property, the docs say:
In .NET 5 and earlier versions, this property only affects code-quality (CAXXXX) rules. Starting in .NET 6, if you set EnforceCodeStyleInBuild to true, this property affects code-style (IDEXXXX) rules too.
Later it talks about AnalysisLevelStyle
property:
AnalysisLevelStyle | All code-style (IDEXXXX) rules
Then later when talking about AnalysisMode
property, the docs say again:
In .NET 5, this property only affects code-quality (CAXXXX) rules. Starting in .NET 6, if you set EnforceCodeStyleInBuild to true, this property affects code-style (IDEXXXX) rules too.
None of the above mentioned properties seem to do anything. And I don’t see how they could. There’s no editor config file named like analysislevelstyle_[...].editorconfig
under 6.0.100/Sdks/Microsoft.NET.Sdk/analyzers/build/config
. And there are no other editorconfig files at all outside of that location in the SDK.
Are the docs wrong and it’s not actually supported or is something missing in the SDK?
To Reproduce
Use VS2022, create a new Asp.Net Core Web project (project type is irrelevant). Open the project and add EnforceCodeStyleInBuild to enable style analyzers:
<PropertyGroup>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
Now try to enable Recommended
mode:
- Add
<AnalysisLevel>6-recommended</AnalysisLevel>
OR - Add
<AnalysisMode>Recommended</AnalysisMode>
OR - Add
<AnalysisLevelStyle>6-recommended</AnalysisLevelStyle>
After each attempt you can observe in VS the rule severity under Dependencies\Analyzers\Microsoft.CodeAnalysis.CSharp.CodeStyle
and see that nothing changes, nearly all rules are at silent
level and a few at suggestion
.
Exceptions (if any)
Further technical details
- Include the output of
dotnet --info
- The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version
Using .Net SDK 6.0.100, VS 2022 17.0.1, on Windows.
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (9 by maintainers)
Top GitHub Comments
The fix for this will be in the 6.0.200 SDK
https://github.com/dotnet/roslyn/issues/58948 appears to be a unrelated to this issue. It is just a continuation of the bugtail for https://github.com/dotnet/roslyn-analyzers/issues/5360. I think I need to rewrite all of how those targets are being generated. it’s too confusing for me to keep track of.