Skip to content

Add RoslynAnalyzers with opt-in properties#53251

Draft
JoeRobich wants to merge 6 commits intomainfrom
dev/jorobich/ship-roslyn-analyzers
Draft

Add RoslynAnalyzers with opt-in properties#53251
JoeRobich wants to merge 6 commits intomainfrom
dev/jorobich/ship-roslyn-analyzers

Conversation

@JoeRobich
Copy link
Member

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:

  • Microsoft.CodeAnalysis.BannedApiAnalyzers
  • Microsoft.CodeAnalysis.PublicApiAnalyzers
  • Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers
  • Microsoft.CodeAnalysis.ResxSourceGenerator

Opt-in properties

All four are opt-in (default false). Users enable them by setting the corresponding MSBuild property:

Property Analyzer
EnableBannedApiAnalysis BannedApiAnalyzers
EnablePublicApiAnalysis PublicApiAnalyzers
EnablePerformanceSensitiveAnalysis PerformanceSensitiveAnalyzers
EnableResxSourceGeneration ResxSourceGenerator

NuGet 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 _ResolveSdkAnalyzerConflicts target) so that it works correctly even against older NuGet package versions that have no awareness of the SDK-bundled analyzers.

What changed

  • redist.csproj — Added PackageReference entries (with ExcludeAssets="All" GeneratePathProperty="true") so the packages are downloaded for layout extraction.
  • GenerateLayout.targets — Extended PublishNETAnalyzers to copy analyzer DLLs and build assets into roslynanalyzers/ 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 _ResolveSdkAnalyzerConflicts dedup target.
  • Version.Details.xml / Version.Details.props / Directory.Packages.props — Added version entries for the three new packages (PublicApiAnalyzers already existed).

@JoeRobich JoeRobich force-pushed the dev/jorobich/ship-roslyn-analyzers branch from 40dce0c to 467efa5 Compare March 4, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant