question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Analysis mode for code style analyzers does not work in .Net SDK 6

See original GitHub issue

Describe 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:

  1. Add <AnalysisLevel>6-recommended</AnalysisLevel> OR
  2. Add <AnalysisMode>Recommended</AnalysisMode> OR
  3. 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:closed
  • Created 2 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
jmarolfcommented, Jan 4, 2022

The fix for this will be in the 6.0.200 SDK

0reactions
jmarolfcommented, Jan 19, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Analysis mode for code style analyzers does not work in . ...
The issue is exactly that the configuration for code styles analyzers (IDExxxx) is nowhere to be found in the SDK, but the documentation...
Read more >
Code analysis in .NET
NET compiler platform (Roslyn) analyzers inspect your C# or Visual Basic code for code quality and style issues. Starting in .
Read more >
Raising Coding Standards with .NET 6.0 Code Analyzers
NET 6.0 makes it easier to take full advantage of code analyzers that can help you improve the quality of your code.
Read more >
Could not load file or assembly 'Microsoft.CodeAnalysis ...
' for code suggestions in VS 2015. An error message comes up saying the following: Could not load file or assembly 'Microsoft.CodeAnalysis, ...
Read more >
Getting started with the Roslyn Analyzers for dotnet
NET (or dotnet if you are in the #dropthedot crowd. ... The Roslyn Analyzers analyze two aspects of your code, Code Style and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found