Add RoslynAnalyzers with opt-in properties#53251
Draft
Conversation
2de7b97 to
40dce0c
Compare
40dce0c to
467efa5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Ship Roslyn analyzers (BannedApi, PublicApi, PerformanceSensitive, ResxSourceGenerator) in the SDK
This change bundles four additional Roslyn analyzer packages into the SDK layout, following the same pattern used for CodeStyle and NetAnalyzers today:
Opt-in properties
All four are opt-in (default
false). Users enable them by setting the corresponding MSBuild property:EnableBannedApiAnalysisEnablePublicApiAnalysisEnablePerformanceSensitiveAnalysisEnableResxSourceGenerationNuGet package dedup
When a project also references one of these packages directly via NuGet, the SDK-bundled copy is automatically removed to avoid duplicate diagnostics. This is handled entirely on the SDK side (via the
_ResolveSdkAnalyzerConflictstarget) so that it works correctly even against older NuGet package versions that have no awareness of the SDK-bundled analyzers.What changed
redist.csproj— AddedPackageReferenceentries (withExcludeAssets="All" GeneratePathProperty="true") so the packages are downloaded for layout extraction.GenerateLayout.targets— ExtendedPublishNETAnalyzersto copy analyzer DLLs and build assets intoroslynanalyzers/subdirectories of the SDK layout.Microsoft.NET.Sdk.Analyzers.targets— Added Enable* property defaults,<Import>of each package's.props/.targets,<Analyzer>item groups gated on the Enable* properties, and the_ResolveSdkAnalyzerConflictsdedup target.Version.Details.xml/Version.Details.props/Directory.Packages.props— Added version entries for the three new packages (PublicApiAnalyzers already existed).