Skip to content

Fix: InitializeStandardNuspecProperties must run before _CalculateInputsOutputsForPack - #17227

Merged
Youssef1313 merged 5 commits into
mainfrom
copilot/initialize-standard-nuspec-properties-before-calcu
Aug 3, 2026
Merged

Fix: InitializeStandardNuspecProperties must run before _CalculateInputsOutputsForPack#17227
Youssef1313 merged 5 commits into
mainfrom
copilot/initialize-standard-nuspec-properties-before-calcu

Conversation

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

NuGet's GetPackOutputItemsTask added NuspecFile and NuspecProperties as inputs to _GetOutputItemsFromPack, which runs inside _CalculateInputsOutputsForPack — before GenerateNuspec. Arcade's InitializeStandardNuspecProperties only declared BeforeTargets="GenerateNuspec", so NuspecProperties was unset when _CalculateInputsOutputsForPack ran, breaking .nuspec-based projects (e.g. aspnetcore).

Changes

  • src/Microsoft.DotNet.Arcade.Sdk/tools/Workarounds.targets: Add _CalculateInputsOutputsForPack to BeforeTargets on InitializeStandardNuspecProperties so NuspecProperties is populated before either pack target reads it.
<Target Name="InitializeStandardNuspecProperties"
        BeforeTargets="GenerateNuspec;_CalculateInputsOutputsForPack"
        ...>

To double check:

Copilot AI review requested due to automatic review settings July 31, 2026 10:39

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.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Copilot AI review requested due to automatic review settings July 31, 2026 10:41

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.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Copilot AI changed the title [WIP] Fix order of InitializeStandardNuspecProperties and _CalculateInputsOutputsForPack Fix: InitializeStandardNuspecProperties must run before _CalculateInputsOutputsForPack Jul 31, 2026
Copilot AI requested a review from Youssef1313 July 31, 2026 10:41
@Youssef1313

Copy link
Copy Markdown
Member

@copilot I think <GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);InitializeStandardNuspecProperties</GenerateNuspecDependsOn> is safer to avoid depending on a private target name.

Copilot AI review requested due to automatic review settings July 31, 2026 10:46

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.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@copilot I think <GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);InitializeStandardNuspecProperties</GenerateNuspecDependsOn> is safer to avoid depending on a private target name.

Done in the latest commit. Replaced BeforeTargets="GenerateNuspec" with GenerateNuspecDependsOn to use the public NuGet extension point. Kept BeforeTargets="_CalculateInputsOutputsForPack" since that's the private target that was changed by NuGet to read NuspecProperties as an incremental-build input — we still need to guarantee ordering there.

Copilot AI review requested due to automatic review settings July 31, 2026 10:48

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

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

Suppressed comments (1)

src/Microsoft.DotNet.Arcade.Sdk/tools/Workarounds.targets:60

  • InitializeStandardNuspecProperties is no longer scheduled to run before _CalculateInputsOutputsForPack. Adding it to GenerateNuspecDependsOn only orders it relative to GenerateNuspec, but _CalculateInputsOutputsForPack can run earlier (and is the target that now consumes NuspecProperties as an incremental input). Re-add BeforeTargets (as described in the PR) so NuspecProperties is populated before both targets execute.
  <Target Name="InitializeStandardNuspecProperties"
          DependsOnTargets="_InitializeNuspecRepositoryInformationPropertiesWorkaround"
          Condition="'$(IsPackable)' == 'true'">

Copilot AI review requested due to automatic review settings July 31, 2026 10:53
@Youssef1313
Youssef1313 marked this pull request as ready for review July 31, 2026 10:53

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

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

@Youssef1313

Copy link
Copy Markdown
Member

dotnet/aspnetcore#68086 (comment) seems like this PR would only fix part of the problem. But I assume the remaining part of the fix will be on NuGet side so that the ID is read from the NuspecProperties.

@Evangelink Evangelink 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 verified this empirically rather than by inspection, and the fix is correct. Notes below — none of them blocking.

Verification

The diagnosis is right. MSBuild runs DependsOnTargets before BeforeTargets. Minimal repro:

== Dep1  →  == Dep2  →  == Before1 (BeforeTargets)  →  == Main

So BeforeTargets="GenerateNuspec" scheduled the target after the entire GenerateNuspec dependency chain, including _CalculateInputsOutputsForPack_GetOutputItemsFromPack.

The fix works. I simulated the real pack target graph (GenerateNuspecDependsOn as built at lines 32/55/59 of NuGet.Build.Tasks.Pack.targets, plus GenerateNuspec DependsOnTargets="$(GenerateNuspecDependsOn);_CalculateInputsOutputsForPack;…"):

what _GetOutputItemsFromPack sees
before (BeforeTargets="GenerateNuspec") NuspecProperties=''
after (GenerateNuspecDependsOn) NuspecProperties='PackageId=Foo;Version=1.2.3'

Import-order robust. NuGet appends $(GenerateNuspecDependsOn) at the tail of its own list and prepends Build;, so this lands last in the list but still strictly before _CalculateInputsOutputsForPack — regardless of whether Workarounds.targets is imported before or after the pack targets.

Moving the target earlier is safe within Arcade. Everything it reads (PackageDescription, PackageLicenseFullPath, PackageIconFullPath, PackageVersion, …) is set at evaluation time in ProjectDefaults.props/.targets; the only target-produced values (RepositoryUrl/RepositoryCommit) come from its own DependsOnTargets. It also matches Pack.targets:5, which already uses this pattern — final chain ends …;InitializeStandardNuspecProperties;_ValidationSymbolPackageFormat, both still ahead of _CalculateInputsOutputsForPack.

Two things not covered by the inline comments

Necessary but not sufficient — worth saying so in the PR body. Per the aspnetcore investigation, GetPackOutputItemsTask unconditionally overwrites packageId with nuspecReader.GetId() whenever NuspecFile != ''. Arcade's $CommonMetadataElements$ composite token means the .nuspec has no literal <id> element, so GetId() returns empty and you get an output path like .11.0.0-dev.nupkg. This PR fixes only the version half. Please state that here and link a NuGet.Client issue so nobody assumes this unblocks aspnetcore on its own.

No regression coverage. There is no project in this repo using NuspecFile or NuspecPackageId, so green CI proves nothing about this code path and it can silently regress again. A scenario test that packs with a NuspecFile + $CommonMetadataElements$ and asserts the emitted nupkg name would be worth it — the "right tests are in" checkbox is still unchecked.

Comment thread src/Microsoft.DotNet.Arcade.Sdk/tools/Workarounds.targets
Comment thread src/Microsoft.DotNet.Arcade.Sdk/tools/Workarounds.targets
To ensure we have set the NuspecProperties early enough, we need to include InitializeStandardNuspecProperties in GenerateNuspecDependsOn.
The GenerateNuspecDependsOn targets are guaranteed to run before _CalculateInputsOutputsForPack.
This was preferred over BeforeTargets="_CalculateInputsOutputsForPack;GenerateNuspec" to avoid depending on a private target name.
-->

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.

Nit: 3-space indent here, the file uses 2 everywhere else.

Also worth splitting the comment block: the original "Workarounds for insufficient support for tools packages…" text describes the <Target>, but it's now separated from it by the new <PropertyGroup>. Keeping that paragraph adjacent to the target and putting the new NuGet-ordering rationale directly above the PropertyGroup would read better.

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.

Line 39 has the 3-space indent. I wouldn't care that much here honestly to make everything in this file consistent.

@Youssef1313
Youssef1313 merged commit 3d13532 into main Aug 3, 2026
11 checks passed
@Youssef1313
Youssef1313 deleted the copilot/initialize-standard-nuspec-properties-before-calcu branch August 3, 2026 17:54
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Aug 4, 2026
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.

InitializeStandardNuspecProperties should run before _CalculateInputsOutputsForPack

5 participants