Preserve dotnetup output and return only the exit code from Invoke-DotnetupNativeCommand#55208
Merged
Merged
Conversation
…tnetupNativeCommand 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>
nagilson
commented
Jul 9, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes PowerShell’s pipeline return behavior in the dotnetup invocation helper so callers receive a real integer exit code while still emitting dotnetup output to the build log, preventing successful dotnetup installs from being misreported as failures during toolset initialization.
Changes:
- Pipe dotnetup native command output to the host (
Out-Host) to keep logs visible and avoid returning stdout as part of the function result. - Ensure
Invoke-DotnetupNativeCommandreturns only$LASTEXITCODE(anInt32) so-ne 0checks behave correctly.
dsplaisted
approved these changes
Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Concern addressed
Fixes the root cause behind spurious
(InitializeToolset) Failed to install .NET SDK(s) ... using dotnetupfailures seen across multiple legs (e.g. build 1499925, PR #53715), where the reported exit code was actually the whole dotnetup install log ending in0.Root cause
Invoke-DotnetupNativeCommand(eng/dotnetup-shared.ps1) ran the dotnetup executable with& \and thenreturn \0. A PowerShell function returns all pipeline output, so the return value was anObject[]= every stdout line from dotnetup plus the exit code, not a single integer.At both call sites (
configure-toolset.ps1bootstrap install andrestore-toolset.ps1runtime install):\ -ne 0compared an array to 0 -> always truthy, so a successful install (exit 0) was misreported as a failure. dotnetup was not actually failing.(exit code '...')text.Repro:
Fix
Route the command's output to the host (
| Out-Host) so it is preserved in the build log, and return only\0so callers get a real integer. Verified: success ->Int32 0(not a failure); genuine failure ->Int32 7(failure) with stderr preserved.The bash path (
RunWithoutErrexit) already captures\Truecorrectly and is unaffected.Draft for CI validation.