Skip to content

Pack generator DLLs via post-build target to fix empty analyzer packages#9785

Merged
glen-84 merged 1 commit into
mainfrom
gai/fix-source-generator-package-emission
May 27, 2026
Merged

Pack generator DLLs via post-build target to fix empty analyzer packages#9785
glen-84 merged 1 commit into
mainfrom
gai/fix-source-generator-package-emission

Conversation

@glen-84

@glen-84 glen-84 commented May 27, 2026

Copy link
Copy Markdown
Member

Summary

  • Source-generator packages (HotChocolate.Types.Analyzers, Mocha.Analyzers, CookieCrumble.Xunit, CookieCrumble.Xunit3) shipped without their generator DLL starting with the 16.0.10 previews — e.g. 16.0.10-p.6 contains only the nuspec. This breaks consumers with error CS0121 on the generated AddTypes() (the call falls back to the two runtime overloads, which a zero-arg call matches ambiguously).
  • Root cause: each csproj packed its DLL via a static <None Include="$(OutputPath)...dll" Pack="true" PackagePath="analyzers/dotnet/cs">. That item is expanded during MSBuild evaluation, before Build runs, so on a clean checkout it globs zero files and packs nothing — with no error. Nuke's separate Compile step used to pre-populate bin/, masking the bug; Remove Nuke; switch CI and release to direct dotnet calls #9772 replaced that with a single-shot dotnet pack, exposing it. Confirmed by package timeline: 16.0.10-p.2 (pre-merge) intact, -p.5/-p.6 (post-merge) empty.
  • Fix: collect the DLL in a TargetsForTfmSpecificContentInPackage target, which runs during nuspec generation after pack's build phase has populated $(OutputPath). No explicit Build dependency, so dotnet pack --no-build still works (an explicit dependency would trip NETSDK1085). For the two multi-targeting CookieCrumble packages, the analyzer is emitted only for net10.0 to avoid a duplicate package-path collision (NU5118).

Test plan

  • Clean single-shot dotnet pack of each of the four projects includes analyzers/dotnet/cs/<generator>.dll (verified via unzip -l).
  • dotnet build then dotnet pack --no-build of each project succeeds (no NETSDK1085) and still includes the analyzer DLL.
  • End-to-end: a HotChocolate web project that previously failed with CS0121 builds successfully against a locally repacked HotChocolate.Types.Analyzers 16.0.10-p.6.
  • Swept all IncludeBuildOutput=false / analyzer-packing csproj files; the *.props/*.targets/*.xaml pack entries are unaffected (static source files present at evaluation time).

Copilot AI left a comment

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.

Pull request overview

Fixes analyzer/source-generator NuGet packages that were shipping without their generator DLLs by moving DLL inclusion from evaluation-time globbing to a pack-time target executed during nuspec generation.

Changes:

  • Replace None Include="$(OutputPath)\*.dll" Pack="true" with a TargetsForTfmSpecificContentInPackage hook that adds TfmSpecificPackageFile items after build output exists.
  • For multi-targeting CookieCrumble.Xunit / CookieCrumble.Xunit3, emit the analyzer DLL only once (for net10.0) to avoid NU5118 duplicate-path collisions.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Mocha/src/Mocha.Analyzers/Mocha.Analyzers.csproj Adds pack-time target to include analyzer DLL(s) into analyzers/dotnet/cs.
src/HotChocolate/Core/src/Types.Analyzers/HotChocolate.Types.Analyzers.csproj Adds pack-time target to include generator DLL(s) into analyzers/dotnet/cs.
src/CookieCrumble/src/CookieCrumble.Xunit/CookieCrumble.Xunit.csproj Adds pack-time target and conditions it to include the analyzer DLL only once.
src/CookieCrumble/src/CookieCrumble.Xunit3/CookieCrumble.Xunit3.csproj Adds pack-time target and conditions it to include the analyzer DLL only once.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@glen-84 glen-84 merged commit d27871c into main May 27, 2026
278 of 280 checks passed
@glen-84 glen-84 deleted the gai/fix-source-generator-package-emission branch May 27, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants