Merge MSBuild functions in tools.ps1/sh#16916
Conversation
... and remove the InitializeToolset call from the functions by calling the nuget cache export function directly
There was a problem hiding this comment.
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
MSBuildandMSBuild-Coreinto a single function in bothtools.ps1andtools.sh, removing theInitializeToolsetcall previously triggered fromMSBuild. - Reordered
tools.ps1soDotNetandEnable-Nuget-EnhancedRetryare now defined alongside the other helpers rather than after the script's bottom initialization block. - Added a top-level
GetNuGetPackageCachePathinvocation at the end of both scripts to ensureNUGET_PACKAGESis still exported even thoughInitializeToolsetis no longer implicitly run byMSBuild.
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
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.
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (1)
eng/common/tools.sh:513
- The bash
MSBuildpreviously exportedNUGET_PLUGIN_HANDSHAKE_TIMEOUT_IN_SECONDS=20andNUGET_PLUGIN_REQUEST_TIMEOUT_IN_SECONDS=20(andWrite-PipelineSetVariable'd them) whenever running under CI. The merged function no longer does that, and the values are not set anywhere else ineng/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 newif [[ "$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
... and remove the InitializeToolset call from the functions by calling the nuget cache export function directly.
The
GetNuGetPackageCachePathfunction all doesn't need a IF CI condition as the function is also unconditionally called in eng/common/build.ps1/sh.The
MSBuild-Corefunction 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-Corepart from the function call).Also remove a set of env vars that are already the default in NuGet now.
To double check: