Skip to content

Implement PackAsAnalyzer convention to include source generators in NuGet packages  #520

@qodo-free-for-open-source-projects

Description

Description

  • Source generator DLLs were missing from NuGet packages because PackAsAnalyzer="true" is a custom convention from dotnet/runtime that is not part of the .NET SDK and was silently ignored
  • Consumers of NuGet packages had no source generation capability because the analyzer DLLs were not included in the analyzers/dotnet/cs/ folder
  • Need to implement the convention properly in the build system to ensure generators are packaged correctly

Deliverables

  • Build-time resolution: Create MSBuild target that sets OutputItemType=Analyzer on ProjectReferences marked with PackAsAnalyzer="true" before compilation
  • Pack-time inclusion: Create MSBuild target that resolves generator DLLs via GetTargetPath and includes them in analyzers/dotnet/cs/ folder in NuGet packages
  • Global application: Import the new targets in Directory.Build.props so all projects using PackAsAnalyzer automatically benefit from the convention

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions