Skip to content

Escape literal output paths before forwarding to MSBuild - #56972

Merged
MiYanni merged 4 commits into
dotnet:mainfrom
MiYanni:miyanni-semicolon-publish-path-escaping
Nov 17, 2026
Merged

MiYanni merged 4 commits into
dotnet:mainfrom
MiYanni:miyanni-semicolon-publish-path-escaping

Conversation

@MiYanni

@MiYanni MiYanni commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

🤖Copilot🤖
Fixes #49671.

Summary

  • Escape CLI-owned literal path options using the existing MSBuildPropertyEscaping utility (ProjectCollection.Escape plus MSBuild command-line comma/quote handling): --output for build, publish, clean, pack, store, and VSTest; --artifacts-path; implicit-restore --packages and --configfile; store --working-dir; and VSTest --settings, --diag, and --results-directory.
  • The definitions keep their default, unescaped path forwarding (through shared ForwardAsOutputPath/ForwardAsPathProperty helpers that accept an optional escaper) so consumers that use the definitions without the managed CLI wiring, notably dotnet-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.
  • Preserve raw user -p: syntax, path normalization, the command-line-defined-output marker, and VSTest quote wrapping.
  • Add 16 filesystem build/publish cases checking actual DLL, PDB, dependency, and runtimeconfig files at the requested paths, plus forwarding tests for the escaping helpers, pack/restore invocation cases, and a dotnet-watch regression test for --output forwarding.

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%20dir previously wrote to out dir and now writes to a folder literally named out%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 (MSBuildOptionExtensionsTests and the build/publish/clean/pack/restore/store/run/test invocation tests, 209 passed, 3 Unix-only skips) and dotnet-watch.Tests CommandLineOptionsTests (193 passed). The filesystem OutputPathOptionTests cases require a full redist layout and are validated in CI.

Earlier validation of the original output-path change:
Reproduced MSB1006 with dotnet 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:

  • 16/16 OutputOptionWritesFilesToLiteralPath cases 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.
  • 16/16 MSBuildOptionExtensionsTests cases 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.
  • Existing build/publish/clean/store/VSTest invocation coverage passed in CLI shard 4: 334 passed, 0 failed, 24 OS skips.
  • Linux managed/AOT and Windows arm64 AOT builds passed. Markdown links and git diff --check passed.

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.

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

Copy link
Copy Markdown
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.

@MiYanni
MiYanni marked this pull request as ready for review November 7, 2026 16:59
@MiYanni
MiYanni requested review from a team, lbussell and mthalman as code owners November 7, 2026 16:59
Copilot AI balanced review requested due to automatic review settings November 7, 2026 16:59

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.

🔵 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 nagilson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

-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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖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 Evangelink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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>
@MiYanni
MiYanni force-pushed the miyanni-semicolon-publish-path-escaping branch from 77cb059 to 0e197e4 Compare November 12, 2026 22:14
@MiYanni MiYanni added the breaking-change Using this label will notify dotnet/compat and trigger a request to file a compat bug label Nov 12, 2026
@MiYanni

MiYanni commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

🤖Copilot🤖
@nagilson Thanks for the list. I fixed these in this PR (0e197e4) so the breaking change is consistent across the CLI's literal path options:

  • pack --output → PackageOutputPath
  • --artifacts-path (build, publish, clean, pack, restore, run, test) → ArtifactsPath
  • --packages / --configfile (implicit restore) → RestorePackagesPath / RestoreConfigFile
  • store --working-dir → ComposeWorkingDir
  • VSTest --settings, --diag, --results-directory → VSTestSetting, VSTestDiag, VSTestResultsDirectory (still quote-wrapped after escaping)

While doing this I found that dotnet-watch builds its own MSBuild arguments from the definitions' forwarding functions, without the managed CLI wiring. Removing --output forwarding from the definitions had silently dropped OutputPath from dotnet watch build/test -o. The definitions now keep their default (unescaped) path forwarding through shared helpers that take an optional escaper, and the managed parsers replace it with MSBuildPropertyEscaping. I added a dotnet-watch regression test for --output. Escaping in dotnet-watch itself remains as it was before this PR.

@dotnet-policy-service

dotnet-policy-service Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this PR and the issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET SDK Breaking Change Notification email list.

You can refer to the .NET SDK breaking change guidelines

@MiYanni

MiYanni commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

🤖Copilot🤖
/azp run dotnet-sdk-public-ci

@MiYanni

MiYanni commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

/azp run dotnet-sdk-public-ci

@azure-pipelines

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

@MiYanni

MiYanni commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

/azp run dotnet-sdk-public-ci

@azure-pipelines

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

@MiYanni

MiYanni commented Nov 16, 2026 •

Copy link
Copy Markdown
Member Author

🤖Copilot🤖
Breaking-change documentation is tracked in dotnet/docs#56926, which links this PR and the original issue #49671. The compatibility article is proposed in dotnet/docs#56927. The documentation PR is a draft pending confirmation of the first shipped SDK version/preview.

@nagilson, could you or another SDK committer send the required .NET SDK Breaking Change Notification email for this change and confirm here once it has been sent?

The notification should cover that the affected CLI path options now preserve literal MSBuild-special characters. For example, --output out%20dir selects the literal directory out%20dir, rather than out dir. Scripts should supply the intended literal path, or use explicit -p: properties when MSBuild interpretation is intentional. The change is planned for .NET 12; the first shipped SDK version/preview is not yet established by this unmerged PR.

Edit: Ignore the bot's comment about an email. This request is small and should not require an email notification.

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@MiYanni
MiYanni merged commit ce8bd32 into dotnet:main Nov 17, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Using this label will notify dotnet/compat and trigger a request to file a compat bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dotnet publish fails when publish directory has a semi-colon

5 participants