Repository navigation
Escape literal output paths before forwarding to MSBuild - #56972
Conversation
Reuse the existing MSBuildPropertyEscaping helper from managed command wiring without adding MSBuild dependencies to shared definitions. Preserve explicit property syntax and cover literal output paths with real build and publish regressions. Fixes dotnet#49671 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🔵 Needs a closer look
Pending rebuilt-SDK Windows filesystem validation leaves literal-path behavior, particularly trailing-backslash handling and VSTest quote wrapping, unverified in this cross-platform MSBuild forwarding change.
No open issues 🎉
What changed in this PR
Fixes #49671 by escaping literal --output paths before forwarding them to MSBuild. The change keeps MSBuild-dependent logic in the managed CLI while preserving explicit -p: syntax and existing path normalization.
Changes:
- Move output-path forwarding from command definitions into managed wiring for build, publish, clean, store, and VSTest.
- Reuse
MSBuildPropertyEscaping, retaining output markers and VSTest quote wrapping. - Add filesystem and forwarding regression tests, and document the managed-only boundary.
| File | Description |
|---|---|
test/dotnet.Tests/OutputPathOptionTests.cs |
Adds 16 build/publish cases checking files at literal output paths. |
test/dotnet.Tests/CommandTests/MSBuild/MSBuildOptionExtensionsTests.cs |
Tests escaping, quoting, absent output, and explicit-property preservation. |
src/Cli/Microsoft.DotNet.Cli.Definitions/Utilities/OptionExtensions.cs |
Removes output-path forwarding from shared definitions. |
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Tool/StoreCommandDefinition.cs |
Defers store output forwarding to managed wiring. |
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Test/TestCommandDefinition.VSTest.cs |
Defers VSTest output forwarding to managed wiring. |
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Publish/PublishCommandDefinition.cs |
Defers publish output forwarding to managed wiring. |
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Clean/CleanCommandDefinition.cs |
Defers clean output forwarding to managed wiring. |
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Build/BuildCommandDefinition.cs |
Defers build output forwarding to managed wiring. |
src/Cli/dotnet/Extensions/MSBuildOptionExtensions.cs |
Adds shared managed forwarding with literal-path escaping. |
src/Cli/dotnet/Commands/Tool/Store/StoreCommandParser.cs |
Wires escaped output forwarding to ComposeDir. |
src/Cli/dotnet/Commands/Test/TestCommandParser.cs |
Wires escaped VSTest output forwarding with quote wrapping. |
src/Cli/dotnet/Commands/Publish/PublishCommandParser.cs |
Wires escaped output forwarding to PublishDir. |
src/Cli/dotnet/Commands/Clean/CleanCommandParser.cs |
Wires escaped clean output forwarding to OutputPath. |
src/Cli/dotnet/Commands/Build/BuildCommandParser.cs |
Wires escaped build output forwarding to OutputPath. |
src/Cli/AGENTS.md |
Documents literal-path escaping and preservation of explicit MSBuild syntax. |
Review effort: Balanced
nagilson
left a comment
There was a problem hiding this comment.
The same unescaped pattern still fails in existing scenarios. This is not a regression, so I'll leave it to you whether you think we should also fix this here, or consider it a different issue.
pack --output ( PackCommandDefinition.cs:28 )
• --artifacts-path ( CommonOptions.cs:188 )
• --packages and --configfile ( ImplicitRestoreOptions.cs:33,49 )
• store --working-dir ( StoreCommandDefinition.cs:55 )
• VSTest --settings , --diag and --results-directory ( TestCommandDefinition.VSTest.cs:18,65,83 )
| } | ||
|
|
||
| // Escape the literal path before adding any MSBuild command-line quoting. | ||
| string propertyValue = MSBuildPropertyEscaping.Escape(fullPath); |
There was a problem hiding this comment.
-o out%20dir used to write to out dir, but now it writes to a folder literally named out%20dir.
We would ideally file this as an intentional breaking change.
There was a problem hiding this comment.
🤖Copilot🤖
Agreed, this is intentional: CLI path options are now literal paths, so -o out%20dir names a folder called out%20dir. I added the breaking-change label to this PR and to #49671 per the breaking change guidelines, and added a Breaking change section to the PR description covering %XX, $(...), @(...), ;, and '. The workaround is to pass the path literally (-o "out dir") or to use an explicit property (-p:OutputPath=out%20dir/), which keeps MSBuild syntax.
Evangelink
left a comment
There was a problem hiding this comment.
No additional actionable findings from the review.
Note
This review was AI-generated.
Preserve the managed literal-path forwarding guidance alongside upstream AOT size and trimming contracts. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Escape remaining CLI-owned path options and keep definition defaults for dotnet-watch Extend literal-path escaping to pack --output, --artifacts-path, --packages, --configfile, store --working-dir, and VSTest --settings/--diag/--results-directory. Restore the definitions' default (unescaped) path forwarding so dotnet-watch, which consumes the definitions without the managed CLI wiring, keeps forwarding these options to its own build. The managed parsers replace that forwarding with MSBuild-escaped values via MSBuildOptionExtensions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
77cb059 to
0e197e4
Compare
|
🤖Copilot🤖
While doing this I found that |
|
Added When you commit this breaking change:
You can refer to the .NET SDK breaking change guidelines |
|
🤖Copilot🤖 |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
🤖Copilot🤖
Edit: Ignore the bot's comment about an email. This request is small and should not require an email notification. |
baronfel
left a comment
There was a problem hiding this comment.
Ok, this makes sense to me after a good read-through. Please prioritize getting the breaking changes doc in for .NET 12 after this though.
🤖Copilot🤖
Fixes #49671.
Summary
MSBuildPropertyEscapingutility (ProjectCollection.Escapeplus MSBuild command-line comma/quote handling):--outputfor build, publish, clean, pack, store, and VSTest;--artifacts-path; implicit-restore--packagesand--configfile; store--working-dir; and VSTest--settings,--diag, and--results-directory.ForwardAsOutputPath/ForwardAsPathPropertyhelpers that accept an optional escaper) so consumers that use the definitions without the managed CLI wiring, notablydotnet-watch, keep forwarding these options to their own builds. The managed command parsers replace that forwarding with MSBuild-escaped values. The AOT-safe definitions assembly gains no MSBuild dependency.-p:syntax, path normalization, the command-line-defined-output marker, and VSTest quote wrapping.dotnet-watchregression test for--outputforwarding.Reuses the repository's existing MSBuild-backed helper rather than the ad-hoc escaping approach discussed in closed, unmerged #52582.
Breaking change
These path options are now treated as literal paths. Characters that MSBuild previously interpreted are no longer reinterpreted, so a value that relied on MSBuild escape sequences or property syntax now names a different path. For example,
dotnet build -o out%20dirpreviously wrote toout dirand now writes to a folder literally namedout%20dir; similarly$(...),@(...),;, and'are no longer evaluated or split.Workaround: pass the intended path literally (for example
-o "out dir"), or pass the MSBuild property explicitly (for example-p:OutputPath=out%20dir/), which keeps MSBuild syntax.Breaking-change documentation: tracking issue and documentation PR.
Validation
Local (Windows x64): targeted
dotnet.Tests(MSBuildOptionExtensionsTestsand the build/publish/clean/pack/restore/store/run/test invocation tests, 209 passed, 3 Unix-only skips) anddotnet-watch.TestsCommandLineOptionsTests(193 passed). The filesystemOutputPathOptionTestscases require a full redist layout and are validated in CI.Earlier validation of the original output-path change:
Reproduced
MSB1006withdotnet publish --output 'out;put'on both the installed .NET 10 SDK and the repository's .NET 12 bootstrap SDK before validating the fix.PR CI build 1668363 rebuilt the SDK and ran the new regressions on Linux x64. The individual outcomes were verified directly in public Helix TRX artifacts, not inferred from build/check counts:
OutputOptionWritesFilesToLiteralPathcases passed: both build and publish wrote the expected files to the exact literal paths for every relative/absolute and trailing-separator combination. CLI shard 3 TRX — 387 passed, 0 failed.MSBuildOptionExtensionsTestscases passed, including Unix-only double quotes/wildcards, literal percent sequences, trailing-separator quote wrapping, absent output, and raw-p:syntax. CLI shard 5 TRX — 465 passed, 0 failed, 1 unrelated skip.git diff --checkpassed.Broader multi-platform CI, including Windows filesystem execution, is still in progress; this PR remains a draft. The local cold redist build was stopped to honor a shared-machine memory-safety hold, so the rebuilt-SDK regression evidence above comes from PR CI rather than a local run.