Skip to content

msbuild: a relative path-fixup probe of project text is assumed to miss, which MSBuild's working directory decides #993

Open

Description

@Smaug123

Found in #992 (#987). After #992, the property expansion applies MSBuild's Unix path fixup (MaybeAdjustFilePath) exactly wherever its probe is absolute, and declines a seed's backslash that meets a relative probe. One known gap remains.

A relative probe of project text is assumed to miss. When the document's own text has a backslash whose rewritten first segment is relative (obj\x), MSBuild probes Directory.Exists("obj") under its working directory, which a served evaluation does not know. The walk assumes the probe misses, so the backslash is kept. That matches MSBuild started from a directory holding none of the segments, but not one started from a directory holding obj/.

Declining instead would decline the SDK's own obj\ and take the NuGet chain with it, so #992 did not. This is the remaining provenance work in docs/msbuild-unix-path-fixup-plan.md.

path_fixup_expansion_diff already runs MSBuild from two working directories. It allows a move between them only where the document's own text holds the \, so this boundary is measured, not hidden.

Options

🤖 Generated with Claude Code

Activity

  1. added
    area:msbuild
    soundness
    on Nov 16, 2026
  2. Smaug123 commented on Nov 19, 2026

    @Smaug123
    CollaboratorAuthor

    This gap now produces a wrong answer that a consumer reads. Codex found it reviewing the fsc assembly-name derivation (#1007).

    Minimal repro (dotnet 10.0.401, macOS). Run MSBuild from the project's directory, which is where dotnet build and every build request run it:

    <Project><PropertyGroup>
      <P>obj\</P>
      <R>FALSE</R>
      <R Condition="'$(P)'=='obj/'">TRUE</R>
    </PropertyGroup><Target Name="Build" /></Project>
    obj/ beside the project obj/ in MSBuild's working directory MSBuild's P / R
    yes no (MSBuild run from elsewhere) obj\ / FALSE
    no yes obj/ / TRUE
    yes yes (MSBuild run from the project's directory) obj/ / TRUE

    The evaluator answers obj\ / FALSE in every row. The rewrite follows the process's working directory, not the project's directory, and it changes the stored property value, not just the comparison.

    The SDK reaches the same state. A restored SDK project has obj/, so dotnet msbuild -getProperty:BaseIntermediateOutputPath, run from the project's directory, prints obj/ once restore has created obj/ and obj\ before. <AssemblyName Condition="'$(BaseIntermediateOutputPath)'=='obj/'">Moved</AssemblyName> builds Moved.dll, but the evaluation trusts AssemblyName as the project name.

    MSBuild code (dotnet/msbuild main at 6d52671ffe4c):

    • src/Build/Evaluation/Expander.cs, ExpandIntoStringLeaveEscaped: result = FileUtilities.MaybeAdjustFilePath(result); (line 260). It passes no base directory.
    • src/Framework/FileUtilities.cs, MaybeAdjustFilePath (line 716) converts \ to / and keeps the result when LooksLikeUnixFilePath holds. LooksLikeUnixFilePath (line 822) defaults an empty baseDirectory to CurrentThreadWorkingDirectory ?? "", which is the process's working directory outside multi-threaded mode. It then checks DirectoryExists(Path.Combine(baseDirectory, firstSegment)).

    Why no differential catches it:

    • fsproj_property_table_diff's generator writes no backslash at all.
    • The resident oracle (msbuild-condition-oracle) inherits the test process's working directory, crates/msbuild, which has no obj/. So the SDK chain's obj\ is only ever graded from a working directory where MSBuild agrees with "the probe misses".

    path_fixup_expansion_diff does vary the working directory, but it allows exactly this movement for project text. That is correct for its own purpose, but nothing downstream treats the value as uncertain.

    #1007 works around it locally: it declines whenever a write from outside the install to AssemblyName, TargetName, TargetExt or OutputType is conditional. The fix belongs here.

  3. added a commit that references this issue on Nov 19, 2026
  4. Smaug123 commented on Nov 19, 2026

    @Smaug123
    CollaboratorAuthor

    Blocking count for #1007's derivation: it declines any document outside the install that holds a condition (NameDecline::Conditional), as a stopgap for this issue. That rule blocks 6/6 pinned project-corpus projects and 97/97 .fsproj files overall: the 24 in the corpus checkouts plus fsharp-src's 73. The count comes from fsc_name_census, an ignored report test in borzoi-msbuild. With this fixed, conditions whose operands are trusted-exact can be admitted again. The sibling rules are tracked in #1061–#1067.

  5. Smaug123 commented on Nov 19, 2026

    @Smaug123
    CollaboratorAuthor

    Correction to the count above: fsharp-src's 73 projects sit under a global.json that selects an SDK the census does not reproduce, so they are now reported as unevaluated rather than counted. The conditions rule blocks 6/6 pinned projects and 24/24 .fsproj files in the corpus checkouts.

  6. 27 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:msbuildsoundness

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions