Skip to content

msbuild: model the Unix path adjustment on every expansion (#987) - #992

Merged
Smaug123 merged 1 commit into
mainfrom
claude/msbuild-user-ext-fixup-987
Nov 16, 2026
Merged

Smaug123 merged 1 commit into
mainfrom
claude/msbuild-user-ext-fixup-987

Conversation

@Smaug123

Copy link
Copy Markdown
Collaborator

Fixes #987.

The rule, from MSBuild 18.9's source

On a non-Windows host every ExpandIntoString… passes each piece of an expansion (a literal run, or what a $(…) returns: Expander.SpanBasedConcatenator) and then the whole value (Expander.ExpandIntoStringLeaveEscaped) through FileUtilities.MaybeAdjustFilePath. The rewrite is kept when the first segment of the rewritten text is a directory. A segment under the root is probed with Path.Combine("", "/seg"), which ignores the working directory, so that answer is a fact of the file system. A relative segment depends on the working directory.

What the fixup does to a value does not depend on where the value came from. What does depend on it is whether the fixup has already run: a property write is stored after expansion, while a global, the environment, a toolset or reserved name, or a task output is stored as given. So the host's MSBuildUserExtensionsPath ($(LocalAppData) + Microsoft\MSBuild) keeps its \ until a body reads it. The read then rewrites it, because /Users (or /home) exists.

The walk applied none of this to bodies. Every body holding a backslash was committed raw and trusted. That included absolute project text, such as $(MSBuildProjectDirectory)\obj\, which MSBuild evaluates to …/obj/.

The change

  • path_fixup::adjust asks each probe: ./.. and the root are directories; any other absolute segment is asked through observed with dotnet_io's Directory.Exists / FileOrDirectoryExists; a relative segment depends on the working directory.
  • properties::substitute adjusts each piece, then the whole value. Each property entry records how MSBuild stored it (Origin::Seed or Origin::Expansion).
  • Two cases decline, with the new PathAdjustmentUndecided diagnostic: a seed's backslash that meets a relative probe, and any absolute probe on the path that asks no file system (parse_fsproj).
  • A relative probe of project text is still taken to miss. That is MSBuild's answer when started from a directory that holds none of the segments. Declining it would decline the SDK's own obj\, and with it the NuGet chain (the deferred provenance dimension in docs/msbuild-unix-path-fixup-plan.md, updated here).
  • A quoted condition operand is expanded, and so adjusted, only when MSBuild's scanner finds something to expand in it (Scanner.ParseQuotedString).
  • Targets run in the project's directory, so the executor declines every relative probe (substitute_in_target). It also declines any item list read beside a backslash, because MSBuild adjusts the list only together with the whole value. Codex found this case in round 2, and the runTargets differential now generates it.

Grading

  • New path_fixup_expansion_diff: MSBuild runs from an empty working directory and from one that holds every generated relative segment. It covers values with \, /, \\, %5c, quotes, ./.., absolute first segments that exist or are missing, relative segments and UNC prefixes. There are five sources: literal, written, global, environment, and the host's MSBuildUserExtensionsPath. There are four read sites: body, condition, Exists, and property function (Combine/Concat). Every commit, with imports or without, must equal MSBuild's value from the empty directory. Where MSBuild's value moves between the two directories, we may commit only if the document's own text holds a \, so any movement that a seed causes must have been declined. The census floors commits per source. I soaked it for 45,000 cases on fresh seeds with no failures. The issue's shape is pinned as a separate test.
  • fsproj_global_perturbation_diff: the body-read shape is back. A new route case reads MSBuildUserExtensionsPath into two bodies and must commit under every global set, and the generator's mixed population can draw it.
  • fsproj_target_execution_generative_diff: identities and values with a backslash next to an item list.
  • late_sdk_seeding_overrides_prior_project_write_to_reserved_toolset_property expected …\NuGet.props raw. MSBuild gives …/NuGet.props, so I updated the expectation. The FSharp.Compiler.Service.Release pure-path snapshot drops two //lex.fs items. Their include needs a probe of /lex.fs, which the pure path cannot make.

Not covered (follow-ups)

  • A relative probe of project text (the plan's remaining provenance work).
  • The executor declines relative probes and absolute probes, because it asks no file system. A target's working directory is the project directory, so both are decidable there.
  • The executor's condition pre-check substitutes the whole condition text, so it also declines a backslash in an operand that MSBuild compares without expanding.
  • MSBuild cannot load a project whose path holds a \ on Unix (MSB4025: it looks for p/q/…), but the walk evaluates it.

Gates

  • cargo fmt --all --check: 0
  • cargo clippy --workspace --all-targets -- -D warnings: 0
  • cargo clippy -p borzoi-msbuild --all-targets --all-features -- -D warnings (final head): 0
  • cargo clippy -p borzoi-msbuild --lib -- -D warnings: 0
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --document-private-items: 0
  • RUSTDOCFLAGS="-D warnings" cargo doc -p borzoi-msbuild --no-deps --document-private-items: 0
  • cargo test --workspace --no-fail-fast: 0. This ran on the head before the executor fix from codex round 2, and the fix touches only msbuild. cargo test -p borzoi-msbuild --no-fail-fast on the final head: 0.
  • fsproj_msbuild_corpus_diff -- --ignored: 0. sdk_chain_decline_attribution -- --ignored: 0.
  • tools/ci/project-corpus-gate.sh: 0. All steps ran before the executor fix; restore-graph and restore-cone were rerun on the final head: 0.

Codex: round 1 had no findings. Round 2 found the item-list boundary issue, now fixed and generated. Round 3 had no findings.

🤖 Generated with Claude Code

MSBuild passes each piece of an expansion (a literal run, a reference's
value) and then the whole expanded value through MaybeAdjustFilePath on a
non-Windows host. A value MSBuild stores without expanding it (a global,
the environment, a toolset or reserved name, a task output) keeps its `\`
until a read adjusts it, so the host's MSBuildUserExtensionsPath
(`$(LocalAppData)` + `Microsoft\MSBuild`) read into a body is
`.../Microsoft/MSBuild` in MSBuild and was committed raw by the walk. The
walk also committed every other backslash-bearing body raw, including
absolute project text such as `$(MSBuildProjectDirectory)\obj\`.

`properties::substitute` now adjusts each piece and then the whole value
(`path_fixup::adjust`): a probe of `.`/`..` hits, an absolute one is asked
through `observed` with .NET's Directory.Exists / FileOrDirectoryExists,
and a relative one turns on the working directory. Property entries record
whether MSBuild stored them as given (`Origin::Seed`) or as an expansion's
result. A seed's backslash that meets a relative probe, and any absolute
probe on the path that asks no file system, declines with the new
`PathAdjustmentUndecided` diagnostic. Project text's relative probe is
still taken to miss: declining it would decline the SDK's own `obj\`
(the deferred provenance dimension of the plan). A quoted condition
operand is expanded, and adjusted, only when MSBuild's scanner saw
something to expand in it. The executor, whose targets run in the
project's directory, declines every relative probe, and any read of an
item list beside a backslash (MSBuild adjusts that list only with the
whole value).

`path_fixup_expansion_diff` holds this to MSBuild started from an empty
working directory and one holding every relative segment, over generated
values from five sources (literal, written, global, environment, the
host's MSBuildUserExtensionsPath) at four read sites (body, condition,
Exists, property function). `fsproj_global_perturbation_diff` now reads
MSBuildUserExtensionsPath into bodies, in a route case that must commit
under every global set and in the generator's mixed population.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

msbuild: $(MSBuildUserExtensionsPath) read into a property body is committed without MSBuild's Unix path fixup

1 participant