Repository navigation
Pass arguments to PowerShell with -File instead of -command - #16363
Merged
Jakub Jareš (nohwnd) merged 3 commits intoAug 18, 2026
Merged
Conversation
build.cmd and test.cmd splice %* unquoted into a powershell -command string, so a semicolon in an argument is parsed as a statement separator. Passing a semicolon-delimited project list to test.cmd -projects executed the trailing .csproj paths, which Windows opens in Visual Studio by file association. Three agent sessions hit this at the same time and opened eighteen IDE instances. Adds a Known Gotchas entry explaining the mechanism, and a pointer from the Build section. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a9a4717a-d9de-4964-81c0-91b6a7c68da3
The .cmd wrappers spliced %* into a powershell -command string, so everything the caller passed was parsed by PowerShell as source code instead of being treated as data. Two things went wrong because of that. A semicolon inside an argument became a statement separator, so test.cmd -projects "test\A\A.csproj;test\B\B.csproj" ran the script with only the first project and then executed the remaining .csproj paths as their own statements, and because .csproj is file-associated with Visual Studio on Windows, each one opened an IDE. Three agents ran that form at the same time and opened eighteen instances of Visual Studio. Separately, -command collapsed every non-zero exit code to 1, so the exit $LastExitCode at the end of eng/build.ps1 never forwarded the real code, including the 8 that means the filter matched no tests. -File passes everything after the script path as a literal argument, so a semicolon separated project list now reaches Arcade intact, which is what its own help text already promises, and exit codes survive. Because arguments are no longer re-parsed, MSBuild properties need one level of quoting instead of two, so the documented single test command in AGENTS.md changes from /p:TestRunnerAdditionalArguments="'--filter Name'" to /p:TestRunnerAdditionalArguments="--filter Name". Both produce the same value. eng/common is left alone, those files come from Arcade. Verified locally: build.cmd succeeds with 0 errors and returns 0, test.cmd -help with a semicolon list in -projects no longer executes the trailing paths and starts no Visual Studio, and a probe script confirms exit codes 0, 8 and 42 now survive where -command turned 8 and 42 into 1. 🤖 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a9a4717a-d9de-4964-81c0-91b6a7c68da3
left a comment
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the Windows .cmd wrappers that invoke the repo’s PowerShell build/test scripts by switching from powershell -command to powershell -File, preventing caller-supplied arguments from being re-parsed as PowerShell source code and preserving non-1 exit codes from the underlying script.
Changes:
- Update repo-owned
.cmdwrappers to usepowershell -File <script> ... %*to pass arguments literally. - Ensure wrapper behavior avoids statement-injection via
;and preserves real exit codes. - Update
AGENTS.mdto document the quoting/argument-passing model and the updated MSBuild property quoting guidance.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| build.cmd | Switch wrapper invocation to powershell -File while forwarding args. |
| test.cmd | Switch wrapper invocation to powershell -File while forwarding args. |
| restore.cmd | Switch wrapper invocation to powershell -File while forwarding args. |
| open-vs.cmd | Switch wrapper invocation to powershell -File while forwarding args. |
| open-code.cmd | Switch wrapper invocation to powershell -File while forwarding args. |
| eng/RestoreInternal.cmd | Switch wrapper invocation to powershell -File while forwarding args. |
| AGENTS.md | Document the -File rationale, injection prevention, and updated quoting examples. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
build.cmd, test.cmd and restore.cmd referenced eng\Build.ps1, but the tracked file is eng/build.ps1. It resolves anyway on case insensitive NTFS, it does not when per directory case sensitivity is enabled, and open-vs.cmd and open-code.cmd already used the lowercase form. Also correct AGENTS.md, it claimed all six wrappers call eng/build.ps1 while eng/RestoreInternal.cmd calls eng/common/build.ps1. From PR review feedback. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a9a4717a-d9de-4964-81c0-91b6a7c68da3
left a comment
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (1)
AGENTS.md:75
- In the wrapper-argument section, this example uses
Build.ps1casing, but the tracked script path in this repo iseng/build.ps1(lowercase). Using the on-disk casing here avoids confusing readers on case-sensitive file systems.
- `;` in an argument became a statement separator. `./test.cmd -projects "test\A\A.csproj;test\B\B.csproj"` ran `Build.ps1 -projects test\A\A.csproj` and then executed `test\B\B.csproj` as its own statement. On Windows `.csproj` is file-associated with Visual Studio, so every entry after the first opened a full IDE. Three agents ran this form at the same time and opened eighteen instances of Visual Studio.
Petr Pokorny (0101)
approved these changes
Aug 18, 2026
This was referenced Aug 18, 2026
This was referenced Oct 13, 2026
This was referenced Oct 15, 2026
Open
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.
The
.cmdwrappers spliced%*into apowershell -commandstring, so anything the caller passed was parsed by PowerShell as source code instead of being treated as data.A semicolon inside an argument therefore became a statement separator. This:
ran
Build.ps1 -projects test\A\A.csprojand then executed the remaining.csprojpaths as their own statements. On Windows.csprojis file-associated with Visual Studio, so every entry after the first opened an IDE. Three agents ran that form at the same time and opened eighteen instances of Visual Studio, which is how I found this. The semicolon separated list is not user error, Arcade's own help text documents-projectsas "Semi-colon delimited list of sln/proj's to build".-commandalso collapsed every non-zero exit code to 1, so theexit $LastExitCodeat the end ofeng/build.ps1never forwarded the real code, including the 8 that means the filter matched no tests.Changes
Switch the repo owned wrappers to
-File, which passes everything after the script path as a literal argument:build.cmdtest.cmdrestore.cmdopen-vs.cmdopen-code.cmdeng/RestoreInternal.cmdeng/common/*is left alone, those files come from Arcade and would have to be fixed there.Because arguments are no longer re-parsed, MSBuild properties need one level of quoting instead of two, so the documented single test command changes from
/p:TestRunnerAdditionalArguments="'--filter TestName'"to/p:TestRunnerAdditionalArguments="--filter TestName". Both deliver the same value to the script. AGENTS.md is updated, and gained a short section explaining why the wrappers use-File.Verification
-projects "a.csproj;<statement>"/p:X="--filter Name""'...'"formbuild.cmdsucceeds locally with 0 errors and returns 0.test.cmd -help -projects "a.csproj;Write-Host INJECTED"prints usage, returns 0, does not run the injected statement, and starts no Visual Studio.🤖