Fix MSBuild property values containing '/dotnet' misinterpreted#53663
Open
chris-peterson wants to merge 1 commit intodotnet:mainfrom
Open
Fix MSBuild property values containing '/dotnet' misinterpreted#53663chris-peterson wants to merge 1 commit intodotnet:mainfrom
chris-peterson wants to merge 1 commit intodotnet:mainfrom
Conversation
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.
Member
|
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. |
Author
I agree 👍 I ended up going further down the rabbit hole: might make sense to keep this change too though given it might take a while for the fix to percolate |
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.
Summary
Fixes #53662
MSBuildArgs.AnalyzeMSBuildArgumentscreates a syntheticSystem.CommandLine.Commandnamed"dotnet"to re-parse forwarded MSBuild arguments.System.CommandLinetreats/<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 thenforwarded to MSBuild as a bare argument (without the
/p:prefix), which MSBuild interprets as a project file path — resulting inMSB1009: Project file does not exist.This was introduced by #49526.
Reproduction
Fix
Rename the synthetic command from
"dotnet"to"__msbuild-args-analysis__"so it is unlikely to collide with values that appear in real MSBuildproperty arguments. Only the command's own name triggers this
System.CommandLinebehavior.Test
Added
PropertyValuesContainingSlashDotnetArePreservedregression test covering both/p:and-p:forms.