From 8b53fbc767c3963cc9926aabbc5f3c09eae8ab9d Mon Sep 17 00:00:00 2001 From: nagilson Date: Wed, 8 Jul 2026 16:28:00 -0700 Subject: [PATCH 1/2] Preserve dotnetup output and return only the exit code from Invoke-DotnetupNativeCommand Invoke-DotnetupNativeCommand ran the dotnetup executable with '& \' and then 'return \0'. Because a PowerShell function returns all pipeline output, the return value was an object array containing every stdout line from dotnetup followed by the exit code -- not a single integer. Consequences at the call sites (bootstrap SDK install in configure-toolset.ps1 and test-runtime install in restore-toolset.ps1): * The '\ -ne 0' check compared an array to 0, which is always truthy, so a successful install (exit code 0) was misreported as a failure. * dotnetup's real progress/diagnostic output was swallowed into the return value and only surfaced, mangled, inside the '(exit code '...')' text of the failure message, e.g. exit code 'Installing .NET SDK ... Installed at ... 0'. Route the command's output to the host so it is preserved in the build log and return only \0, so callers receive a real integer exit code. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/dotnetup-shared.ps1 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/eng/dotnetup-shared.ps1 b/eng/dotnetup-shared.ps1 index 67e01ee4aeda..fad2735d3cef 100644 --- a/eng/dotnetup-shared.ps1 +++ b/eng/dotnetup-shared.ps1 @@ -68,7 +68,15 @@ function Invoke-DotnetupNativeCommand([scriptblock]$Command) { $ErrorActionPreference = 'Continue' $PSNativeCommandUseErrorActionPreference = $false try { - & $Command + # Route the command's output to the host rather than this function's + # pipeline. This keeps dotnetup's progress and any error/diagnostic output + # visible (and preserved) in the build log, and -- critically -- prevents + # that output from being returned alongside the exit code. If it were + # captured, the caller would receive an object array (every stdout line + # plus the exit code) instead of a single integer, so an '-ne 0' check + # would always be truthy and a successful install (exit code 0) would be + # misreported as a failure. + & $Command | Out-Host return $LASTEXITCODE } catch { From 67dedec2adee9ae9de8543ff9d6545af18d8ed60 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Thu, 9 Jul 2026 10:05:11 -0700 Subject: [PATCH 2/2] simplify justification to improve readability --- eng/dotnetup-shared.ps1 | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/eng/dotnetup-shared.ps1 b/eng/dotnetup-shared.ps1 index fad2735d3cef..420d9916f5c5 100644 --- a/eng/dotnetup-shared.ps1 +++ b/eng/dotnetup-shared.ps1 @@ -68,14 +68,7 @@ function Invoke-DotnetupNativeCommand([scriptblock]$Command) { $ErrorActionPreference = 'Continue' $PSNativeCommandUseErrorActionPreference = $false try { - # Route the command's output to the host rather than this function's - # pipeline. This keeps dotnetup's progress and any error/diagnostic output - # visible (and preserved) in the build log, and -- critically -- prevents - # that output from being returned alongside the exit code. If it were - # captured, the caller would receive an object array (every stdout line - # plus the exit code) instead of a single integer, so an '-ne 0' check - # would always be truthy and a successful install (exit code 0) would be - # misreported as a failure. + # Write command output to the host and prevent it from being returned alongside the exit code & $Command | Out-Host return $LASTEXITCODE }