Skip to content

Fix Unix paths normalization in properties in /mt mode.#13439

Merged
AR-May merged 4 commits intodotnet:mainfrom
AR-May:fix-unix-paths
Mar 24, 2026
Merged

Fix Unix paths normalization in properties in /mt mode.#13439
AR-May merged 4 commits intodotnet:mainfrom
AR-May:fix-unix-paths

Conversation

@AR-May
Copy link
Copy Markdown
Member

@AR-May AR-May commented Mar 23, 2026

Fixes #13425

Context

Blazor WASM builds (and other projects) fail under /mt mode on Unix with DirectoryNotFoundException because paths contain unresolved backslashes, e.g.:

obj\Debug/net8.0/Net8BlazorWasmApp.csproj.AssemblyReference.cache

The root cause is in FileUtilities.LooksLikeUnixFilePath. This method checks whether the value looks like a unix path by checking whether the first path segment (e.g., obj) actually exists as a directory. It is used in FileUtilities.MaybeAdjustFilePath which decides whether a string with backslashes should be normalized to forward slashes. However, LooksLikeUnixFilePath, when base directory is not passed to the method, relies on CWD for the directory existence check. This breaks in /mt mode.

Changes Made

Use CurrentThreadWorkingDirectory for resolving the absolute path to check for existence, when base path is not provided.

Testing

  • Tested on local repro, this fixes the original issue.
  • Unit test.

Copilot AI review requested due to automatic review settings March 23, 2026 13:23
@AR-May AR-May self-assigned this Mar 23, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Unix path normalization under /mt by ensuring the Unix-path heuristic doesn’t rely on the process-wide current working directory when no base directory is provided, avoiding unresolved backslashes in generated paths.

Changes:

  • Update FileUtilities.LooksLikeUnixFilePath to resolve directory-existence checks against FileUtilities.CurrentThreadWorkingDirectory when baseDirectory is empty.
  • Prevent /mt builds on Unix from incorrectly treating backslash-containing relative paths as non-path strings due to CWD mismatches.

AR-May and others added 3 commits March 23, 2026 14:26
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@AR-May AR-May merged commit d84a0dc into dotnet:main Mar 24, 2026
10 checks passed
dfederm pushed a commit to dfederm/msbuild that referenced this pull request Apr 9, 2026
Fixes dotnet#13425

### Context
Blazor WASM builds (and other projects) fail under /mt mode on Unix with
`DirectoryNotFoundException` because paths contain unresolved
backslashes, e.g.:
```
obj\Debug/net8.0/Net8BlazorWasmApp.csproj.AssemblyReference.cache
```

The root cause is in `FileUtilities.LooksLikeUnixFilePath`. This method
checks whether the value looks like a unix path by checking whether the
first path segment (e.g., obj) actually exists as a directory. It is
used in `FileUtilities.MaybeAdjustFilePath` which decides whether a
string with backslashes should be normalized to forward slashes.
However, `LooksLikeUnixFilePath`, when base directory is not passed to
the method, relies on CWD for the directory existence check. This breaks
in /mt mode.

### Changes Made
Use `CurrentThreadWorkingDirectory` for resolving the absolute path to
check for existence, when base path is not provided.

### Testing
- Tested on local repro, this fixes the original issue.
- Unit test.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.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.

Build failure in /mt mode – Blazor WASM build fails on Unix.

3 participants