Skip to content

Preserve dotnetup output and return only the exit code from Invoke-DotnetupNativeCommand#55208

Merged
nagilson merged 3 commits into
dotnet:mainfrom
nagilson:nagilson-preserve-dotnetup-output
Jul 9, 2026
Merged

Preserve dotnetup output and return only the exit code from Invoke-DotnetupNativeCommand#55208
nagilson merged 3 commits into
dotnet:mainfrom
nagilson:nagilson-preserve-dotnetup-output

Conversation

@nagilson

@nagilson nagilson commented Jul 8, 2026

Copy link
Copy Markdown
Member

Concern addressed

Fixes the root cause behind spurious (InitializeToolset) Failed to install .NET SDK(s) ... using dotnetup failures seen across multiple legs (e.g. build 1499925, PR #53715), where the reported exit code was actually the whole dotnetup install log ending in 0.

Root cause

Invoke-DotnetupNativeCommand (eng/dotnetup-shared.ps1) ran the dotnetup executable with & \ and then return \0. A PowerShell function returns all pipeline output, so the return value was an Object[] = every stdout line from dotnetup plus the exit code, not a single integer.

At both call sites (configure-toolset.ps1 bootstrap install and restore-toolset.ps1 runtime install):

  • \ -ne 0 compared an array to 0 -> always truthy, so a successful install (exit 0) was misreported as a failure. dotnetup was not actually failing.
  • dotnetup's real progress/diagnostic output was swallowed into the return value and only surfaced, mangled, inside the (exit code '...') text.

Repro:

STRINGIFIED: 'Installing SDK...  Installed at X: .NET SDK 11  0'
(-ne 0) => treated as failure? True     # even though exit code was 0

Fix

Route the command's output to the host (| Out-Host) so it is preserved in the build log, and return only \0 so 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 \True correctly and is unaffected.

Draft for CI validation.

…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>
Comment thread eng/dotnetup-shared.ps1 Outdated
@nagilson nagilson marked this pull request as ready for review July 9, 2026 17:05
Copilot AI review requested due to automatic review settings July 9, 2026 17:05
@nagilson nagilson requested review from a team and MichaelSimons July 9, 2026 17:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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-DotnetupNativeCommand returns only $LASTEXITCODE (an Int32) so -ne 0 checks behave correctly.

@nagilson nagilson merged commit f0f0fe5 into dotnet:main Jul 9, 2026
27 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 10, 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.

3 participants