Skip to content

Merge MSBuild functions in tools.ps1/sh#16916

Merged
ViktorHofer merged 3 commits into
mainfrom
ConsolidateMSBuildFunctionsAndFollowuponPackageCache
Jun 1, 2026
Merged

Merge MSBuild functions in tools.ps1/sh#16916
ViktorHofer merged 3 commits into
mainfrom
ConsolidateMSBuildFunctionsAndFollowuponPackageCache

Conversation

@ViktorHofer
Copy link
Copy Markdown
Member

@ViktorHofer ViktorHofer commented May 29, 2026

... and remove the InitializeToolset call from the functions by calling the nuget cache export function directly.

The GetNuGetPackageCachePath function all doesn't need a IF CI condition as the function is also unconditionally called in eng/common/build.ps1/sh.

The MSBuild-Core function is not used by anyone aside from the entry point in the VMR which I will update with the next re-bootstrap (just remove the -Core part from the function call).

Also remove a set of env vars that are already the default in NuGet now.

To double check:

... and remove the InitializeToolset call from the functions by calling the nuget cache export function directly
Copilot AI review requested due to automatic review settings May 29, 2026 08:12
@ViktorHofer ViktorHofer requested a review from akoeplinger May 29, 2026 08:13
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

Refactors the MSBuild helper in eng/common/tools.ps1 and eng/common/tools.sh by collapsing the previous MSBuild + MSBuild-Core wrapper pair into a single MSBuild function, dropping the InitializeToolset call that the wrapper used to make, and instead invoking GetNuGetPackageCachePath once at script-load time so the NuGet package cache environment variables are still exported.

Changes:

  • Merged MSBuild and MSBuild-Core into a single function in both tools.ps1 and tools.sh, removing the InitializeToolset call previously triggered from MSBuild.
  • Reordered tools.ps1 so DotNet and Enable-Nuget-EnhancedRetry are now defined alongside the other helpers rather than after the script's bottom initialization block.
  • Added a top-level GetNuGetPackageCachePath invocation at the end of both scripts to ensure NUGET_PACKAGES is still exported even though InitializeToolset is no longer implicitly run by MSBuild.
Show a summary per file
File Description
eng/common/tools.ps1 Merges MSBuild/MSBuild-Core, relocates DotNet and Enable-Nuget-EnhancedRetry, and calls GetNuGetPackageCachePath at script-load.
eng/common/tools.sh Merges MSBuild/MSBuild-Core and calls GetNuGetPackageCachePath at script-load.

Note: eng/common is mirrored from Arcade, so making these changes in dotnet/arcade is correct. The behavioral change to export NUGET_PACKAGES at script source time (rather than lazily on first InitializeToolset call) affects every consumer that sources tools.ps1/tools.sh, including scripts that never invoke MSBuild; this widens blast radius beyond the MSBuild callers.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@ViktorHofer ViktorHofer changed the title Merge MSBuild functiosn in tools.ps1/sh Merge MSBuild functions in tools.ps1/sh May 29, 2026
Comment thread eng/common/tools.ps1 Outdated
Comment thread eng/common/tools.ps1 Outdated
All the env vars removed in this commit are already the default in NuGet, there's no need anymore to set them.

The two plugin env vars have a slightly different value but that shouldn't matter (20 vs 30s). The settings is from eight years ago when the default didn't exist.

Also rename the GetNuGetPackageCachePath function to InitializeNuGetPackageCachePath to not imply that the function only returns data without side effects. WPF is the only repository that currently uses that function name. I'm gonna update that when it flows to that repo.
Copilot AI review requested due to automatic review settings May 29, 2026 12:46
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.

Copilot's findings

Comments suppressed due to low confidence (1)

eng/common/tools.sh:513

  • The bash MSBuild previously exported NUGET_PLUGIN_HANDSHAKE_TIMEOUT_IN_SECONDS=20 and NUGET_PLUGIN_REQUEST_TIMEOUT_IN_SECONDS=20 (and Write-PipelineSetVariable'd them) whenever running under CI. The merged function no longer does that, and the values are not set anywhere else in eng/common. This is a behavior change that isn't called out in the PR description; if the intent is to drop these, please mention it, otherwise restore them inside the new if [[ "$ci" == true ]] block to keep parity with the previous behavior (and with the PowerShell side once it's also restored).
function MSBuild {
  if [[ "$ci" == true ]]; then
    if [[ "$binary_log" != true && "$exclude_ci_binary_log" != true ]]; then
      Write-PipelineTelemetryError -category 'Build'  "Binary log must be enabled in CI build, or explicitly opted-out from with the -noBinaryLog switch."
      ExitWithExitCode 1
    fi

    if [[ "$node_reuse" == true ]]; then
      Write-PipelineTelemetryError -category 'Build'  "Node reuse must be disabled in CI build."
      ExitWithExitCode 1
    fi
  fi
  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread eng/common/tools.ps1
@ViktorHofer ViktorHofer merged commit fa92642 into main Jun 1, 2026
11 checks passed
@ViktorHofer ViktorHofer deleted the ConsolidateMSBuildFunctionsAndFollowuponPackageCache branch June 1, 2026 06:38
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.

3 participants