Skip to content

Propagate dotnet.exe exit code from eng/common/dotnet.ps1 - #7214

Merged
ViktorHofer merged 1 commit into
dotnet:mainfrom
akoeplinger:FixDotnetPs1ExitCode
Jun 15, 2026
Merged

ViktorHofer merged 1 commit into
dotnet:mainfrom
akoeplinger:FixDotnetPs1ExitCode

Conversation

@akoeplinger

Copy link
Copy Markdown
Member

When a CI step invokes eng/common/dotnet.cmd ... on Windows (e.g. signing validation), a non-zero exit from dotnet.exe is silently dropped and the step is marked green even when the build failed. Reproduces in #6019: on Mac/Linux, a failing dotnet build correctly fails the AzDO step (yellow with continueOnError: true); on Windows the same failure shows as green ✓.

Root cause

On Windows the invocation chain is:

AzDO pwsh task
  → pwsh.exe
    → dotnet.cmd
      → powershell.exe -command "& dotnet.ps1 ..."
        → dotnet.exe build ...

dotnet.ps1:

if ($args.count -gt 0) {
  $env:DOTNET_NOLOGO=1
  & "$dotnetRoot\dotnet.exe" $args
}

When dotnet.exe returns 1:

  1. $LASTEXITCODE inside dotnet.ps1 is 1.
  2. The script ends with a native invocation and no exit $LASTEXITCODE, so the spawned powershell.exe exits 0.
  3. dotnet.cmd reads %ErrorLevel% (= 0 from the powershell.exe call) and does exit /b 0.
  4. The outer pwsh script sees a successful invocation and the AzDO step is green.

dotnet.sh is unaffected because bash propagates the last command's exit status by default.

Fix

Call ExitWithExitCode $LASTEXITCODE after invoking dotnet.exe, matching the convention already used by the other eng/common/*.ps1 scripts that invoke native tools (msbuild.ps1, sdk-task.ps1, build.ps1, dotnet-install.ps1, etc.).

Patched in two places:

  • src/arcade/eng/common/dotnet.ps1 — the upstream-flowing source of truth.
  • eng/common/dotnet.ps1 — the VMR top-level copy, so the fix takes effect in VMR pipelines immediately. Per-repo copies under src/*/eng/common/ will pick this up via arcade code flow.

When a CI step invokes `eng/common/dotnet.cmd build ...` on Windows
(e.g. signing validation), a non-zero exit from dotnet.exe is silently
dropped: the chain is pwsh -> dotnet.cmd -> powershell.exe -> dotnet.ps1
-> dotnet.exe. dotnet.ps1's last statement is a native invocation
`& "$dotnetRoot\dotnet.exe" $args`, with no `exit $LASTEXITCODE`,
so the spawned powershell.exe exits 0 even when dotnet.exe returned 1.
dotnet.cmd then reports `%ErrorLevel%` = 0 and the outer pwsh step is
marked green even though the build failed. dotnet.sh is unaffected
because bash propagates the last command's exit status by default.

Call `ExitWithExitCode $LASTEXITCODE` after invoking dotnet.exe so the
exit code surfaces to callers, matching the convention already used by
the other eng/common/*.ps1 scripts (msbuild.ps1, sdk-task.ps1,
build.ps1, dotnet-install.ps1, etc).

Apply the same change to the mirrored copy at eng/common/dotnet.ps1 so
the fix takes effect in the VMR immediately; per-repo eng/common copies
under src/*/eng/common/ will pick this up via arcade code flow.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 12, 2026 15:49
@akoeplinger
akoeplinger requested review from a team as code owners June 12, 2026 15:49
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team June 12, 2026 15:49
@akoeplinger
akoeplinger requested a review from ViktorHofer June 12, 2026 15:51

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

This PR aims to ensure Windows CI correctly fails when eng/common/dotnet.cmd invokes dotnet.exe and dotnet.exe returns a non-zero exit code, aligning behavior with macOS/Linux where the exit status is naturally propagated.

Changes:

  • Add ExitWithExitCode $LASTEXITCODE after invoking dotnet.exe in src/arcade/eng/common/dotnet.ps1.
  • Add the same exit-code propagation logic in the VMR copy eng/common/dotnet.ps1.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/arcade/eng/common/dotnet.ps1 Adds explicit exit-code propagation after running dotnet.exe.
eng/common/dotnet.ps1 Mirrors the same change in the VMR top-level copy so pipelines pick it up immediately.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread eng/common/dotnet.ps1 Resolved
@akoeplinger

Copy link
Copy Markdown
Member Author

Behavior-change analysis

I audited all callers of eng/common/dotnet.{cmd,ps1} in the VMR. Most invocations come through a subprocess boundary (AzDO script: steps, dotnet.cmd → powershell.exe -command ...), where the fix is purely a bug fix — the exit code now propagates correctly and there's no observable change beyond CI steps now failing when they should.

There is one class of callers worth flagging explicitly: in-process & dotnet.ps1 ... invocations from inside another .ps1. In PowerShell, exit from a &-invoked script terminates the calling host, so these scripts will now abort on a non-zero dotnet exit code instead of silently continuing.

Identified in-process callers in the VMR:

Location Pattern
src/fsharp/tests/ILVerify/ilverify.ps1:45 (& dotnet.ps1 msbuild ... --getProperty:FSharpNetCoreProductTargetFramework).Trim()
src/fsharp/eng/build-utils.ps1:18 same pattern
src/fsharp/eng/Build.ps1:86 same pattern
src/fsharp/eng/test-determinism.ps1:408 same pattern
src/arcade/azure-pipelines-daily.yaml:43 Get-ChildItem ... |% { & dotnet.ps1 secret-manager synchronize ... }

For the four F# scripts, the prior behavior was that a failed dotnet msbuild --getProperty silently returned an empty/garbage string and the script continued with a wrong TFM. The new behavior is that the script aborts immediately with the dotnet exit code — almost certainly the intended behavior; silently using a wrong TFM is a worse failure mode than an abrupt abort.

For arcade's azure-pipelines-daily.yaml:43, previously all vault-config files were processed and only the last $LASTEXITCODE was visible. Now the first failure aborts the loop. Same reasoning — likely an improvement, but worth noting.

I don't think any of these need changes alongside this PR — they were all latent bugs that this fix now surfaces correctly. Flagging in case reviewers want to weigh in.

@ViktorHofer
ViktorHofer merged commit 02aeba1 into dotnet:main Jun 15, 2026
9 of 11 checks passed
@akoeplinger
akoeplinger deleted the FixDotnetPs1ExitCode branch June 15, 2026 08:16
@akoeplinger

Copy link
Copy Markdown
Member Author

/backport to release/10.0.1xx

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0.1xx (link to workflow run)

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.

4 participants