Skip to content

[Breaking change]: CLI path options preserve literal MSBuild-special characters #56926

Open

Description

@MiYanni

🤖Copilot🤖

Description

The .NET CLI escapes CLI-owned literal path option values before forwarding them to MSBuild. Paths containing MSBuild-special characters are no longer interpreted as MSBuild syntax. For example, dotnet build -o out%20dir previously selected out dir and now selects the literal directory out%20dir.

Implementation: dotnet/sdk#56972
Original issue: dotnet/sdk#49671
Required process: https://github.com/dotnet/sdk/blob/main/documentation/project-docs/breaking-change-guidelines.md#required-process-for-all-net-sdk-breaking-changes

Verified against SDK PR head 0e197e4a9951ff264203b051d511fa1da9a41d2c. The managed parsers apply the existing MSBuildPropertyEscaping utility. Explicit user -p: values retain their existing MSBuild interpretation. The shared definitions retain their unescaped default for consumers such as dotnet watch; this change does not add literal-path escaping to dotnet watch.

Version

Other (please put exact version in description textbox)

Planned for .NET 12. The source branch's eng/Versions.props identifies SDK 12.0.100 with prerelease label alpha and iteration 1. The implementation PR is still open and unmerged, has no milestone, and does not establish a first shipped SDK build or public preview. Confirm the first released version before publishing the compatibility article; do not infer Preview 1 from the development version.

Previous behavior

The CLI resolved path option values to full paths and forwarded them to MSBuild without escaping MSBuild-special characters. MSBuild could decode percent escape sequences or interpret other syntax. A valid filesystem path containing a semicolon could fail with MSB1006, including a relative output path whose full path contained a semicolon.

For example, dotnet build --output out%20dir wrote to out dir, not to a directory literally named out%20dir.

New behavior

The managed CLI parsers escape the full path before forwarding it as an MSBuild property, while preserving existing path normalization and required quote wrapping. The affected options are:

Option Commands
--output / -o dotnet build, dotnet publish, dotnet clean, dotnet pack, dotnet store, and dotnet test in VSTest mode.
--artifacts-path dotnet build, dotnet publish, dotnet clean, dotnet pack, dotnet restore, dotnet run, and dotnet test (both VSTest and Microsoft.Testing.Platform modes).
--packages and --configfile Shared restore-option forwarding in dotnet restore, dotnet build, dotnet publish, and dotnet pack.
--working-dir dotnet store.
--settings, --diag, and --results-directory dotnet test in VSTest mode.

For example, dotnet build --output out%20dir now selects the literal directory out%20dir. The CLI does not reinterpret percent escape sequences or MSBuild property/item syntax in these path values. Filesystem restrictions and shell quoting rules still apply.

Type of breaking change

  • Binary incompatible: Existing binaries might encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code might require source changes to compile successfully.
  • Behavioral change: Existing binaries might behave differently at run time.

Reason for change

To treat path options as filesystem paths rather than MSBuild expressions, the CLI must escape characters before it forwards them to MSBuild. The fix addresses valid output directories that contain semicolons and avoids unintended MSBuild interpretation of other path characters.

Recommended action

Pass the desired path literally. For example, replace dotnet build --output out%20dir with dotnet build --output "out dir" if the intended directory contains a space. Remove any MSBuild-specific pre-escaping from values supplied to the affected path options. Continue to quote or escape arguments as required by the shell.

If a script intentionally requires MSBuild syntax, pass the corresponding property explicitly instead of the CLI path option. For example, dotnet build -p:OutputPath=out%20dir/ retains MSBuild escape interpretation, and dotnet publish -p:PublishDir=out%20dir/ does the same for publish output. Raw -p: syntax is unchanged; this change adds no SdkAnalysisLevel, target-framework, or feature-switch opt-out.

Feature area

SDK

Affected APIs

None. This change affects .NET CLI option behavior, not managed API signatures.

The SDK-side linking, label updates, and request for a committer to notify the .NET SDK Breaking Change Notification email list are coordinated separately. No notification email is claimed to have been sent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🗺️ reQUESTbreaking-change

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions