Skip to content

Restore NUGET_PACKAGES export at CI initialization#16899

Merged
ViktorHofer merged 1 commit into
dotnet:mainfrom
akoeplinger:fix/restore-nuget-packages-export-in-ci
May 29, 2026
Merged

Restore NUGET_PACKAGES export at CI initialization#16899
ViktorHofer merged 1 commit into
dotnet:mainfrom
akoeplinger:fix/restore-nuget-packages-export-in-ci

Conversation

@akoeplinger
Copy link
Copy Markdown
Member

@akoeplinger akoeplinger commented May 27, 2026

Note

This PR was authored with assistance from GitHub Copilot.

Fixes #16898.

Problem

#16814 ("Remove the Arcade msbuild logger") removed the InitializeToolset call from the MSBuild function in eng/common/tools.{sh,ps1} along with the ArcadeLogging.dll wiring. InitializeToolset had a load-bearing side effect: it calls GetNuGetPackageCachePath, which exports NUGET_PACKAGES.

Repos that enter Arcade via eng/common/build.{sh,ps1} are unaffected because build.{sh,ps1} calls InitializeToolset directly. Repos that enter via eng/common/msbuild.{sh,ps1} (e.g. dotnet/runtime's src/tests/build.sh) no longer get NUGET_PACKAGES exported.

The downstream effect:

  • NuGet restore falls back to ~/.nuget/packages/.

  • RepoLayout.props still sets MSBuild's $(NuGetPackageRoot) to $(RepoRoot)/.packages/ when ContinuousIntegrationBuild=true.

  • Generated .nuget.g.props imports guarded by Exists($(NuGetPackageRoot)…) are silently skipped.

  • Properties contributed by those imports (e.g. XunitConsoleNetCoreAppPath) end up undefined, and downstream targets fail. Example failure observed in dotnet/runtime CI:

    external.csproj(81,5): error : looks the package Microsoft.DotNet.XUnitConsoleRunner is not restored or missing xunit.console.dll.
    

Fix

Restore the InitializeToolset call in the MSBuild function (gated on $ci), matching the location and gating semantics from before #16814.

  • InitializeToolset is idempotent (caches via _InitializeToolset / $global:_InitializeToolset).
  • InitializeBuildTool is not re-added: MSBuild-Core already calls it on its own code path, and InitializeToolset invokes DotNet / InitializeDotNetCli itself on the cold path when it needs to restore the Arcade SDK.
  • Placing the call in the MSBuild function (rather than at tools.{sh,ps1} load time) ensures any repo-specific configure-toolset.{sh,ps1} overrides — including use_global_nuget_cache / $useGlobalNuGetCache — have already been imported before GetNuGetPackageCachePath runs.

Validation

Copilot AI review requested due to automatic review settings May 27, 2026 19:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR restores CI initialization of NUGET_PACKAGES for Arcade entry points that source eng/common/tools.{sh,ps1} without going through build.{sh,ps1}, addressing the restore/build package-root mismatch described in #16898.

Changes:

  • Adds CI-gated GetNuGetPackageCachePath initialization in Bash tooling.
  • Adds the equivalent CI-gated initialization in PowerShell tooling.
  • Documents the regression source and why the initialization is needed.

Reviewed changes

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

File Description
eng/common/tools.sh Exports NUGET_PACKAGES during CI initialization for Bash-based entry points.
eng/common/tools.ps1 Exports NUGET_PACKAGES during CI initialization for PowerShell-based entry points.

Comment thread eng/common/tools.sh Outdated
Comment thread eng/common/tools.ps1 Outdated
@ViktorHofer
Copy link
Copy Markdown
Member

I would restore the previous behavior by adding the InitializeToolset calls back to tools.ps1 and tools.sh in that exact place where it got removed.

When the Arcade msbuild logger was removed in dotnet#16814, the
InitializeToolset call in the MSBuild function (tools.{sh,ps1}) was
removed alongside it. That call had a load-bearing side effect:
InitializeToolset invokes GetNuGetPackageCachePath, which exports
NUGET_PACKAGES.

Without NUGET_PACKAGES exported, NuGet restore defaults to the user
profile while RepoLayout.props sets MSBuild's $(NuGetPackageRoot) to
$(RepoRoot)/.packages/ under ContinuousIntegrationBuild=true. Generated
.nuget.g.props imports guarded by Exists($(NuGetPackageRoot)...) are
silently skipped, and properties contributed by them (e.g.
XunitConsoleNetCoreAppPath) end up undefined.

Restore the InitializeToolset call in the MSBuild function gated on
$ci, matching the pre-dotnet#16814 behavior. Placing it in the MSBuild
function rather than at tools.{sh,ps1} load time ensures any
configure-toolset overrides have already been imported.

Fixes dotnet#16898

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@akoeplinger akoeplinger force-pushed the fix/restore-nuget-packages-export-in-ci branch from 8c69a21 to 6de2cf2 Compare May 28, 2026 07:29
@akoeplinger
Copy link
Copy Markdown
Member Author

@ViktorHofer done

@ViktorHofer
Copy link
Copy Markdown
Member

Wouldn't it be great to have force merge permissions for such cases ;)

@ViktorHofer ViktorHofer enabled auto-merge (squash) May 29, 2026 06:46
@ViktorHofer ViktorHofer merged commit 0353e2e into dotnet:main May 29, 2026
9 of 10 checks passed
@akoeplinger akoeplinger deleted the fix/restore-nuget-packages-export-in-ci branch May 29, 2026 12:24
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone May 30, 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.

eng/common/msbuild.{sh,ps1} no longer exports NUGET_PACKAGES in CI (regression from #16814)

3 participants