Skip to content

Fix NormalizePath and other intrinsic functions in multithreaded mode - #14875

Merged
AR-May merged 4 commits into
dotnet:mainfrom
AR-May:fix-vs-mt-normalize-path
Sep 3, 2026
Merged

AR-May merged 4 commits into
dotnet:mainfrom
AR-May:fix-vs-mt-normalize-path

Conversation

@AR-May

@AR-May AR-May commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #14872.

In MT mode, each project uses a thread-local working directory while the process current directory is shared. [MSBuild]::NormalizePath and other intrinsic functions ignored the thread-local directory and resolved relative paths against the process directory, which could produce valid-looking absolute paths rooted under the wrong project or host directory.

This change combines the path arguments, resolves relative paths against FileUtilities.CurrentThreadWorkingDirectory when available, and then applies the existing normalization. Non-MT behavior and already-absolute paths remain unchanged.

@AR-May
AR-May force-pushed the fix-vs-mt-normalize-path branch 4 times, most recently from 2db0083 to baec47b Compare August 28, 2026 15:36
Resolve relative intrinsic paths against the thread-local project directory while preserving legacy behavior when no thread directory is active.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9b67edba-e376-4e0d-b0f8-1c03c139047a
@AR-May
AR-May force-pushed the fix-vs-mt-normalize-path branch from baec47b to ab8defa Compare September 1, 2026 13:54
@AR-May AR-May changed the title Fix NormalizePath in multithreaded mode Fix NormalizePath and other intrinsic functions in multithreaded mode Sep 1, 2026
@AR-May
AR-May marked this pull request as ready for review September 1, 2026 13:55
@AR-May
AR-May requested review from JanProvaznik and a lite review from Copilot September 1, 2026 13:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Pull request overview

This PR fixes multi-threaded (-mt) evaluation path resolution for [MSBuild] intrinsic functions so that relative paths are resolved against FileUtilities.CurrentThreadWorkingDirectory (project-local, thread/AsyncLocal) rather than the process-wide current directory, preventing “valid-looking” absolute paths rooted under the wrong directory.

Changes:

  • Update [MSBuild] intrinsics (NormalizePath, FileExists, DirectoryExists, MakeRelative, GetDirectoryNameOfFileAbove, GetPathOfFileAbove) to resolve relative inputs via the thread working directory when available.
  • Add a dedicated set of -mt-mode unit tests validating the corrected behavior (including Unix/Windows-specific edge cases like backslash-rooted paths and drive-relative paths).
File summaries
File Description
src/Build/Evaluation/IntrinsicFunctions.cs Resolve intrinsic-function relative paths against FileUtilities.CurrentThreadWorkingDirectory in -mt mode (with special handling for separator/rootedness semantics).
src/Build.UnitTests/Evaluation/Expander_Tests.cs Add tests covering -mt thread working directory behavior for updated [MSBuild] intrinsics (and ensure parity with non--mt behavior).
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@JanProvaznik JanProvaznik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd revert the makerelative change and fix buildcheck (+ test for that)

MakeRelative documents basePath as "Must be absolute", so resolving it
against the thread working directory only ever changed behavior for
callers already outside the contract. Reverted, along with its test.

RegisterBuildCheck had the same class of bug the rest of this change
fixes: GetFullPathNoThrow resolves against the process current
directory, so in -mt mode a relative check assembly path was looked up
under whichever project happened to own the process directory. It now
resolves against the thread working directory first.

Also corrected a test comment that claimed FileExists applies no
separator normalization; FileExistsNoThrow does normalize internally,
and the point of the test is that -mt and non-mt agree.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 447caa92-1ebd-4a5e-b3d3-02ffbb220532
@AR-May
AR-May requested a review from JanProvaznik September 2, 2026 08:09
Three of the new NormalizePath tests compared a path built from the
TestEnvironment folder against a path resolved through the process current
directory. On macOS the temp folder is reached through the /var ->
/private/var symlink, and Directory.GetCurrentDirectory reports the resolved
form while TestEnvironment reports the unresolved one, so the two spellings of
the same directory did not compare equal.

Build both sides from the directory as the OS reports it. Product behavior is
unchanged; only the tests were wrong.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 447caa92-1ebd-4a5e-b3d3-02ffbb220532
@AR-May
AR-May enabled auto-merge (squash) September 2, 2026 09:06
@AR-May
AR-May merged commit e6a9a3c into dotnet:main Sep 3, 2026
10 checks passed
github-actions Bot added a commit that referenced this pull request Sep 7, 2026
Recurring cross-platform correctness issue flagged in PR #14916 (bot
review) and PR #14875 (JanProvaznik) — inline test XML metadata values
used hardcoded backslashes, which are invalid path separators on
Unix. Added a clarifying clause near the existing NormalizeSlashes
guidance in tests.instructions.md.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AR-May pushed a commit that referenced this pull request Sep 8, 2026
…XML (#14973)

## What changed
Added one clarifying sentence to
`.github/instructions/tests.instructions.md`, appended to the existing
line about `NormalizeSlashes`/cross-platform path comparisons: a note
that item/metadata path values in inline test XML must not hardcode `\`
as a separator (invalid on Unix) and should be built with `Path.Combine`
instead.

## Why
This is a recurring cross-platform correctness miss in test PRs this
week:
- PR #14916 ("Resolve PathLike MatchOnMetadata against the thread
working directory"): a bot review flagged hardcoded `\` in inline test
XML metadata (`M1='...\sub\file.txt'`), which produces invalid paths on
Linux/macOS and breaks the intended assertion.
- PR #14875 ("Fix NormalizePath and other intrinsic functions in
multithreaded mode"): review discussion (Copilot + JanProvaznik)
centered on the same class of path-separator/normalization confusion
recurring "in the same file."

Both PRs are in the multithreading/path-normalization area and both
needed a reviewer to catch a hardcoded-backslash-in-test-XML issue —
exactly the kind of miss a short instruction-file note prevents up
front.

I checked the existing `tests.instructions.md` content and confirmed no
existing bullet already states this — the nearest related guidance
(`NormalizeSlashes for cross-platform path comparisons`) covers
*comparison* but not *construction* of test XML path values, so this is
a minimal in-place amendment rather than a duplicate.

## Reviewers (core MSBuild team)
Suggested reviewers — could not verify individual `@dotnet/kitten` team
membership via the API (404), falling back to team mention:
``@dotnet/kitten``

> [!WARNING]
> <details>
> <summary>Firewall blocked 1 domain</summary>
>
> The following domain was blocked by the firewall during workflow
execution:
>
> - `github.com`
>
> To allow these domains, add them to the `network.allowed` list in your
workflow frontmatter:
>
> ```yaml
> network:
>   allowed:
>     - defaults
>     - "github.com"
> ```
>
> See [Network
Configuration](https://github.github.com/gh-aw/reference/network/) for
more information.
>
> </details>

> Generated by [Dreaming (learning atoms
curation)](https://github.com/dotnet/msbuild/actions/runs/34156507739) ·
copilot · auto · 53.9 AIC · ⌖ 9.11 AIC · ⊞ 12.3K ·
[◷](https://github.com/search?q=repo%3Adotnet%2Fmsbuild+%22gh-aw-workflow-id%3A+dreaming.agent%22&type=pullrequests)

<!-- gh-aw-agentic-workflow: Dreaming (learning atoms curation), engine:
copilot, model: auto, id: 34156507739, workflow_id: dreaming.agent, run:
https://github.com/dotnet/msbuild/actions/runs/34156507739 -->

<!-- gh-aw-workflow-id: dreaming.agent -->
<!-- gh-aw-workflow-call-id: dotnet/msbuild/dreaming.agent -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Nov 16, 2026
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]::NormalizePath ignores the thread working directory in MT mode

3 participants