Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<AnalysisLevel>latest-all</AnalysisLevel> seems to be not effective when switching to .NET7 #65630

Closed
moses70 opened this issue Nov 28, 2022 · 4 comments
Labels
Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@moses70
Copy link

moses70 commented Nov 28, 2022

Version Used:
SDK 7.0.100 with Visual studio 17.4.1

Steps to Reproduce:

  1. Install .NET6 SDK and .NET 7 SDK in parallel (latest versions)
  2. Create a C# project with a global.json selecting .NET6
  3. Use <AnalysisLevel>latest-all</AnalysisLevel> in csproj
  4. Using some example code, targeting .NET48 with <EnableNETAnalyzers>true</EnableNETAnalyzers>
  5. Verify the number of code analysis warnings. E.g. 97 warnings
  6. Switch to .NET7 using global.json, rebuild
  7. The number of code analysis warnings decreases to about the same number as with <AnalysisLevel>latest-recommended</AnalysisLevel>

Diagnostic Id:

For example, CA2007 should be enabled in "latest-all", but is not in .NET7

Expected Behavior:
In .NET7, at least the same number of code style warnings should be visible as in .NET 6.

Actual Behavior:
latest-all has not the same effect in .NET 7

Workaround
With this global.json, I can still use C#11 features (with VS17.4) and all analyzers are working:
{
"sdk": {
"allowPrerelease": false,
"version": "6.0.0",
"rollForward": "latestMinor"
}
}

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 28, 2022
@Youssef1313
Copy link
Member

Youssef1313 commented Nov 28, 2022

@mavasani Is this the issue fixed in dotnet/roslyn-analyzers#6246 ?

@mavasani
Copy link
Contributor

@mavasani Is this the issue fixed in dotnet/roslyn-analyzers#6246 ?

Seems very likely. @moses70 Can you please check if adding an explicit NuGet package reference to https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet7/NuGet/Microsoft.CodeAnalysis.NetAnalyzers/versions fixes the issue? This fix has been inserted into the dotnet/sdk repo and should be part of the next .NET 7 servicing patch.

@moses70
Copy link
Author

moses70 commented Nov 28, 2022

Works for me!
Thank you for the quick response and workaround.

@mavasani
Copy link
Contributor

Duplicate of dotnet/roslyn-analyzers#6245

@mavasani mavasani marked this as a duplicate of dotnet/roslyn-analyzers#6245 Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants