Skip to content

Work around MSVC path limits in Windows CoreCLR builds - #137259

Merged
jkoritzinsky merged 2 commits into
mainfrom
krwq-clean-windows-build-failure
Nov 18, 2026
Merged

jkoritzinsky merged 2 commits into
mainfrom
krwq-clean-windows-build-failure

Conversation

@krwq

@krwq krwq commented Nov 10, 2026

Copy link
Copy Markdown
Member

Note

This change and PR description were prepared with assistance from GitHub Copilot.

Problem

I've been hitting Windows build failures when using the Copilot app, which creates isolated worktrees under paths like:

C:\Users\kwicher\.copilot\repos\copilot-worktrees\runtime\krwq-effective-tribble
C:\Users\kwicher\.copilot\repos\copilot-worktrees\runtime\krwq-laughing-meme

This is a normal app-generated checkout path, but adding the native build directories and target names produces object paths longer than MSVC can handle. In this case, a NativeAOT descriptor object path reaches 266 characters and cl.exe fails with:

fatal error C1083: Cannot open compiler generated file: '': Invalid argument

Windows long paths were already enabled. The compiler still rejects this output path, and adding a \\?\ prefix does not help.

Workaround

For Windows-target CoreCLR builds using Ninja, use the existing Windows 8.3 spelling of the intermediate directory as Ninja's working directory. Pass it through cmake --build using Ninja's -C option, since passing the alias to CMake alone expands it back to the long path.

This keeps the existing targets, output locations, compiler settings and CMake parallelism settings. It does not create aliases, change filesystem settings or add drive mappings.

The common scenario this addresses is building from a nested checkout such as a Copilot app worktree on a Windows volume where short aliases are available. It is not unrestricted long-path support: NTFS aliases are not guaranteed, ReFS does not provide them, and sufficiently long paths may still require a shorter checkout. The Windows build documentation now explains those limits.

Validation

Windows x64, using the default Ninja build:

  • Before the workaround, .\build.cmd clr+libs -rc Release failed with the C1083 error above.
  • With the final workaround, .\build.cmd clr+libs -rc Release passed with zero MSBuild warnings or errors. All nine NativeAOT descriptor objects were deleted before this run and rebuilt; this was not another entirely clean checkout build.
  • The longest underlying descriptor object paths remain 266 characters. Their effective spelling through the short working directory is 235 characters, addressing the same files.
  • Verified unchanged compiler commands, retained embedded debug information and a byte-identical generated main contract descriptor.
  • Checked command selection, paths with spaces, parallelism settings and failure propagation with a scratch harness. The MSBuild branch was checked for command construction only; other platforms and a real MSBuild build were not run.
  • git diff --check passed.

Related to #110407 and #60812. This targets CoreCLR's Windows Ninja build and does not resolve every scenario in those issues.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Comment thread src/coreclr/build-runtime.cmd Resolved
Remove the target-OS gate and the documentation paragraph per review.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants