Skip to content

Fix argument forwarding and stage logging in eng/build.ps1 - #14767

Merged
ViktorHofer merged 2 commits into
mainfrom
FixBuildPs1OutputLogging
Aug 20, 2026
Merged

ViktorHofer merged 2 commits into
mainfrom
FixBuildPs1OutputLogging

Conversation

@ViktorHofer

Copy link
Copy Markdown
Member

Context

build.cmd -v minimal currently prints the wrapper's internal command string and then silently ignores the verbosity:

> build.cmd -v minimal
Stage 1 build: $global:LASTEXITCODE = 1
& 'C:\git\msbuild2\eng\common\build.ps1' -configuration Debug -restore -build minimal
exit $LASTEXITCODE

Two separate problems are visible there: the log line leaks exit-code plumbing, and minimal arrives as a bare property instead of -verbosity minimal.

Changes

Logging. The quoting logic is split out of Get-BuildCommand, so the logged text is just the Arcade invocation, without the $global:LASTEXITCODE = 1 prologue and trailing exit $LASTEXITCODE.

Argument forwarding. PowerShell binds arguments against this script's parameters before they are ever forwarded, so undeclared Arcade arguments could be swallowed or misrouted:

Argument Previous behavior
-v minimal bound the common -Verbose switch; minimal leaked in as a bare property
-b (Arcade's -build) prefix-matched the local -binaryLog, silently turning a build into a binlog request

-verbosity and -build are now declared so those arguments bind to the right parameter, and every bound parameter is forwarded generically from $PSBoundParameters instead of per-parameter if blocks.

Only parameters this script actually reads are declared. Everything else flows through $properties verbatim and is bound by Arcade, which keeps Arcade's [bool] parameters (-nodeReuse, -msbuildMultiThreaded, -warnAsError) working without mirroring them here — mirroring them would require marshalling, since True/False re-parse as strings rather than booleans through pwsh -Command.

Two smaller fixes. -binaryLogName My.binlog now yields My.stage2.binlog for stage 2 rather than forwarding one name to both stages, and an empty argument is no longer appended when no extra properties are passed.

Testing

  • Swept all 35 Arcade parameters plus every alias through the wrapper into a stub that reports what bound: 0 failures.
  • Verified the CI invocations produce identical stage 1 / stage 2 command lines (-ci -test -stage2Argument /mt, -ci -test -stage2Argument '/p:RunQuarantinedTests=true').
  • Verified pass-through of /p:Foo=Bar, -warnnotaserror 'NU1901;NU1902', -mt 1, -nodeReuse 0, -sign -pack -publish, -pb -projects.
  • Ran a real build.cmd -v quiet: build succeeded and the verbosity took effect.

The "Stage 1 build:" log line printed the internal command string,
including the `$global:LASTEXITCODE = 1` prologue and the trailing
`exit $LASTEXITCODE`, which is plumbing rather than something the caller
can act on. Split the quoting out of Get-BuildCommand so the logged text
is just the Arcade invocation.

Arguments were also not reaching eng/common/build.ps1 reliably, because
PowerShell binds them against this script's parameters first:

- `-v minimal` bound the common `-Verbose` switch, so `minimal` arrived
  as a bare property and the verbosity was silently dropped.
- `-b` (Arcade's `-build`) prefix-matched the local `-binaryLog`
  parameter, silently turning a build request into a binlog request.

Declare `-verbosity` and `-build` so those arguments are claimed by the
right parameter, and forward every bound parameter generically from
$PSBoundParameters instead of maintaining per-parameter if-blocks. Only
parameters this script reads are declared; everything else flows through
$properties verbatim and is bound by Arcade, so Arcade's [bool]
parameters such as -nodeReuse and -msbuildMultiThreaded keep working
without needing to be mirrored here.

Also give the stage 2 binary log a distinct name when -binaryLogName is
supplied, instead of forwarding the same name to both stages, and stop
appending an empty argument when no extra properties are passed.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b8bee071-e10a-4013-9ec6-d87a006fb4dd
Copilot AI lite review requested due to automatic review settings August 20, 2026 07:03
@ViktorHofer
ViktorHofer requested a review from a team as a code owner August 20, 2026 07:03

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 the eng/build.ps1 wrapper so Arcade arguments are forwarded correctly (avoiding PowerShell common-parameter/prefix binding pitfalls) and stage command logging is cleaner and more representative of the actual Arcade invocation.

Changes:

  • Adds/adjusts wrapper parameters and forwards all explicitly bound parameters via $PSBoundParameters (excluding locally handled ones) to prevent -v minimal / -b mis-binding.
  • Splits quoting from command construction and logs only the Arcade invocation (not $LASTEXITCODE plumbing).
  • Improves binlog naming for stage 2 when -binaryLogName is provided, and avoids appending an empty argument when $properties is null.
Show a summary per file
File Description
eng/build.ps1 Corrects parameter binding/forwarding, refines command logging output, and adjusts stage-2 binlog naming and argument handling.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Suppressed comments (2)

eng/build.ps1:58

  • The comment says only bound parameters are forwarded so Arcade defaults are preserved, but -configuration is always forwarded (defaulting to Debug), which contradicts the comment and can confuse future edits. Please clarify the comment (or change behavior).
# Forward every explicitly supplied parameter to the Arcade build. Only bound parameters are forwarded,
# so parameters the caller didn't pass keep their Arcade defaults instead of being pinned to this
# script's. Parameters listed here are handled by this script and must not be forwarded verbatim.
$locallyHandledParameters = @('configuration', 'test', 'stage2', 'stage2Argument', 'binaryLogName', 'properties')

eng/build.ps1:122

  • Leaving the old if ($stage2) block commented out adds noise and makes it unclear whether stage 1 logging is intended to be conditional. Either restore the condition or remove the commented-out lines.
# if ($stage2) {
  Write-Host "Stage 1 build: $(Get-BuildCommandForDisplay $buildArgs)"
# }
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread eng/build.ps1 Resolved
- Escape single quotes in the build script path once, in a shared
  $quotedBuildScript, so Get-BuildCommandForDisplay matches the escaping
  Get-BuildCommand already did. A repo path containing a quote otherwise
  rendered an invalid command line.
- Clarify that -configuration is always forwarded, unlike the parameters
  that are only forwarded when bound.
- Drop the commented-out `if ($stage2)` around the stage 1 log line.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b8bee071-e10a-4013-9ec6-d87a006fb4dd
@ViktorHofer
ViktorHofer requested a review from AR-May August 20, 2026 08:14
@AR-May

AR-May commented Aug 20, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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