Document how to configure code analyzers in legacy projects #48803
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #27744
Summary
This PR adds documentation on how to configure code analyzers when using the Microsoft.CodeAnalysis.NetAnalyzers NuGet package in legacy (non-SDK-style) .NET Framework projects.
Problem
The existing documentation mentions that MSBuild properties like
AnalysisMode
andAnalysisLevel
only work with SDK-style projects starting with .NET 5, and suggests using the Microsoft.CodeAnalysis.NetAnalyzers NuGet package for legacy projects. However, it doesn't explain how to configure the analyzers when using the NuGet package, leaving users without guidance on how to enable additional analyzers or adjust rule severity.Solution
Added a new section "Configure analyzers in legacy projects" to
docs/fundamentals/code-analysis/overview.md
that documents three configuration methods available for legacy projects:EditorConfig files: The primary method for configuring rule severity and options. Includes examples showing how to:
Predefined configurations: Explains how to use the pre-packaged EditorConfig and ruleset files included in the NuGet package, which are located in the
editorconfig
andrulesets
subdirectories after installation.Ruleset files: Documents this deprecated-but-still-supported method with appropriate deprecation notice, showing how to create and reference ruleset files in the project file.
The new section clearly explains that MSBuild properties like
AnalysisMode
andAnalysisLevel
don't work for projects that don't reference a project SDK, and provides actionable alternatives with concrete examples.Related Links
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.