Skip to content

Fix GetPackOutputItems when nuspec does not exist - #7565

Merged
zivkan merged 1 commit into
devfrom
dev-zivkan-GetPackOutputItemsTask-nuspec-not-found
Jul 15, 2026
Merged

zivkan merged 1 commit into
devfrom
dev-zivkan-GetPackOutputItemsTask-nuspec-not-found

Conversation

@zivkan

@zivkan zivkan commented Jul 15, 2026

Copy link
Copy Markdown
Member

Bug

Fixes: NuGet/Home#14711
follow up from #7531

Description

Code flow into the .NET VMR failed: dotnet/dotnet#7703

Copilot says it's because roslyn has build customization where their analyzer packages generate their own nuspec file: https://github.com/dotnet/roslyn/blob/f8235426959cd1ffb2b6cbeb6feb2d21238f61b8/eng/targets/GenerateAnalyzerNuspec.targets#L139-L140

They seemingly do this to avoid restore cyclic references: https://github.com/dotnet/roslyn/blob/f8235426959cd1ffb2b6cbeb6feb2d21238f61b8/src/RoslynAnalyzers/Microsoft.CodeAnalysis.BannedApiAnalyzers/Core/Microsoft.CodeAnalysis.BannedApiAnalyzers.csproj#L5-L9

Their GenerateAnalyzerNuspecFile target uses BeforeTargets="GenerateNuspec", but MSBuild's execution order is DependsOn, then BeforeTargets, then the target itself, followed by AfterTargets. Since GenerateNuspec uses DependsOn for GetPackOutputItems, it means that it runs before roslyn's GenerateAnalyzerNuspecFile target. Therefore, the nuspec file doesn't exist at the time #7531 changes try to read the file.

This means that in the situation where a generated nuspec uses a package name different to what the MSBuild property PackageId value, then GetPackOutputItemsTask will generate filenames different to what GenerateNuspec (that actually generates nupkgs) creates.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc. N/A

@zivkan
zivkan requested a review from a team as a code owner July 15, 2026 05:28

@nkolev92 nkolev92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's a very unfortunate timing that GetPackOutputItems can be out of date with PackTask.

Like all the effort in the fix we made was to ensure those 2 are always equivalent.

I understand this is the practical fix, but not in love with this.

@nkolev92
nkolev92 force-pushed the dev-zivkan-GetPackOutputItemsTask-nuspec-not-found branch from 708e625 to f740eed Compare July 15, 2026 17:34
@nkolev92

Copy link
Copy Markdown
Member

@zivkan I rebased so that the tests pass.

cc @NuGet/nuget-client We need an approval here for merge. This PR carries some urgency because it's blocking code flow.

@zivkan
zivkan merged commit 6880988 into dev Jul 15, 2026
20 of 21 checks passed
@zivkan
zivkan deleted the dev-zivkan-GetPackOutputItemsTask-nuspec-not-found branch July 15, 2026 23:31
@Youssef1313

Copy link
Copy Markdown
Contributor

Should Roslyn be updated so that their GenerateAnalyzerNuspecFile runs early enough?

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.

Cannot determine correct nupkg output file name when nuspec metadata overrides PackageId/Version

4 participants