Skip to content

Fix MSBuild property values containing '/dotnet' misinterpreted#53663

Open
chris-peterson wants to merge 1 commit intodotnet:mainfrom
chris-peterson:fix/msbuild-property-slash-dotnet-parsing
Open

Fix MSBuild property values containing '/dotnet' misinterpreted#53663
chris-peterson wants to merge 1 commit intodotnet:mainfrom
chris-peterson:fix/msbuild-property-slash-dotnet-parsing

Conversation

@chris-peterson
Copy link
Copy Markdown

Summary

Fixes #53662

MSBuildArgs.AnalyzeMSBuildArguments creates a synthetic System.CommandLine.Command named "dotnet" to re-parse forwarded MSBuild arguments.
System.CommandLine treats /<command-name> inside option values as a reference to the command itself, so any /p: property value containing
/dotnet (e.g., /p:DockerImage=registry.example.com/myproject/dotnet) causes the parser to silently reject the token. The rejected value is then
forwarded to MSBuild as a bare argument (without the /p: prefix), which MSBuild interprets as a project file path — resulting in MSB1009: Project file does not exist.

This was introduced by #49526.

Reproduction

mkdir repro && cd repro
dotnet new console
dotnet msbuild -p:MyProp=something/dotnet   # MSB1009
dotnet msbuild -p:MyProp=something/other    # works

Fix

Rename the synthetic command from "dotnet" to "__msbuild-args-analysis__" so it is unlikely to collide with values that appear in real MSBuild
property arguments. Only the command's own name triggers this System.CommandLine behavior.

Test

Added PropertyValuesContainingSlashDotnetArePreserved regression test covering both /p: and -p: forms.

AnalyzeMSBuildArguments creates a synthetic System.CommandLine command to
re-parse forwarded MSBuild arguments. The command was named "dotnet",
which caused System.CommandLine to interpret '/<command-name>' (i.e.
'/dotnet') inside /p: option values as a reference to the command itself.
This silently rejected the entire token, so the property never reached
MSBuild, resulting in MSB1009.

Rename the synthetic command to '__msbuild-args-analysis__' so it is
unlikely to collide with values that appear in real MSBuild property
arguments.
@baronfel
Copy link
Copy Markdown
Member

baronfel commented Apr 1, 2026

I think this would work around the issue, but the more concerning thing to me is why S.CL has the parsing behavior is does. That feels like a foot gun to me.

@chris-peterson
Copy link
Copy Markdown
Author

chris-peterson commented Apr 1, 2026

@baronfel

why S.CL has the parsing behavior is does. That feels like a foot gun to me.

I agree 👍

I ended up going further down the rabbit hole:
dotnet/command-line-api#2789

might make sense to keep this change too though given it might take a while for the fix to percolate

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSBuild property values containing '/dotnet' are silently dropped, causing MSB1009

2 participants