Skip to content

Resolve analyzers from the analyzers group in project.assets.json#54646

Draft
martinrrm wants to merge 1 commit into
mainfrom
mruizmares-analyzer-assets
Draft

Resolve analyzers from the analyzers group in project.assets.json#54646
martinrrm wants to merge 1 commit into
mainfrom
mruizmares-analyzer-assets

Conversation

@martinrrm

Copy link
Copy Markdown
Contributor

Summary

This is the SDK (build) half of the "indicate analyzer assets in project.assets.json" feature (spec: NuGet/Home#14455). It teaches ResolvePackageAssets to consume the new analyzers group that NuGet restore writes into project.assets.json, instead of scanning every file under analyzers/ in each package.

Note

Draft until the companion NuGet restore change ships (NuGet/Home#6279). The local NuGet.config and eng/Version.Details.props edits in this branch point the build at a locally-built NuGet and must not be merged — they exist only to validate end-to-end against the in-progress restore change.

What changes

When restore has recorded RestoreEnableAnalyzerAssets in the assets file (opt-in, gated to .NET 11+ on the restore side), ResolvePackageAssets now:

  • Reads analyzers from the analyzers group in each package's target rather than scanning library.Files. The group already has PrivateAssets / ExcludeAssets / IncludeAssets applied by restore.
  • Selects by metadata instead of parsing paths:
    • codeLanguage must match the project language, or be language-agnostic (any);
    • among compiler-version-specific analyzers the highest applicable compilerApiVersion wins; if the project's compiler version is unknown, every variant is treated as version-agnostic.
  • Honors the restore decision, not the raw MSBuild property. The decision reads RestoreMetadata.RestoreEnableAnalyzerAssets persisted in the assets file, because the .NET 11 TFM gate lives in NuGet's targets (not imported at build). When the feature is enabled but a package has no analyzers group, the SDK does not fall back to legacy scanning.
  • Preserves legacy behavior when the feature is off (the default): the existing path-based AnalyzerResolver scanning is used unchanged.
  • Emits Low-importance diagnostics for each analyzer included/excluded and why, visible at -v detailed, matching the selection-tracing style used elsewhere in these tasks.


if (!IsApplicableAnalyzerLanguage(asset, projectCodeLanguage))
{
_task.Log.LogMessage(MessageImportance.Low, $"Excluding analyzer '{asset.Path}' from package '{library.Name}' because its code language does not apply to the project language '{projectCodeLanguage}'.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this message be localized?

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.

2 participants