From 7bb37a50c915a2d29f1ed82d78ed70f7f8592497 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 13 Apr 2026 18:50:42 +0200 Subject: [PATCH 1/3] Add early long path validation to Windows build script On Windows machines without long path support enabled, the build fails in hard-to-diagnose ways deep in the build process. This adds a check at the start of eng/build.ps1 that: - Tries to create a temp file with a path exceeding 260 characters - If it fails, exits early with a clear error message pointing to docs/workflow/requirements/windows-requirements.md#enable-long-paths - If it succeeds, writes a stamp file (artifacts/.long-path-validated) so subsequent builds skip the check Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/build.ps1 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/eng/build.ps1 b/eng/build.ps1 index 1401f5c72b55ca..fe0dd135e9a34b 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -135,6 +135,50 @@ function Get-Help() { Write-Host "For more information, check out https://github.com/dotnet/runtime/blob/main/docs/workflow/README.md" } +function Check-LongPathSupport() { + $repoRoot = Split-Path $PSScriptRoot -Parent + $artifactsDir = Join-Path $repoRoot "artifacts" + $stampFile = Join-Path $artifactsDir ".long-path-validated" + + if (Test-Path $stampFile) { + return + } + + $testDir = Join-Path $artifactsDir "tmp" + if (-not (Test-Path $testDir)) { + New-Item -ItemType Directory -Path $testDir -Force | Out-Null + } + + # Build a file path that exceeds the 260-character MAX_PATH limit. + $basePath = Join-Path $testDir "longpath_test_" + $padLength = [Math]::Max(32, 270 - $basePath.Length) + $testPath = $basePath + ("a" * $padLength) + ".tmp" + + try { + [System.IO.File]::WriteAllText($testPath, "test") + Remove-Item $testPath -Force -ErrorAction SilentlyContinue + } + catch { + Write-Host "" + Write-Host "ERROR: Long file paths are not enabled on this system." -ForegroundColor Red + Write-Host "The dotnet/runtime repository requires long path support to build successfully." -ForegroundColor Red + Write-Host "" + Write-Host "Please follow the instructions at:" -ForegroundColor Yellow + Write-Host " docs\workflow\requirements\windows-requirements.md#enable-long-paths" -ForegroundColor Yellow + Write-Host "" + Write-Host "Quick fix:" -ForegroundColor Yellow + Write-Host " 1. Enable long paths in Windows (requires admin):" -ForegroundColor White + Write-Host " https://learn.microsoft.com/windows/win32/fileio/maximum-file-path-limitation" -ForegroundColor White + Write-Host " 2. Enable long paths in Git:" -ForegroundColor White + Write-Host " git config --system core.longpaths true" -ForegroundColor White + Write-Host "" + exit 1 + } + + # Validation passed - stamp so we skip this check on subsequent builds. + [System.IO.File]::WriteAllText($stampFile, "Long path support validated on $(Get-Date)") +} + if ($help) { Get-Help exit 0 @@ -152,6 +196,8 @@ if ($subset -eq 'help') { exit 0 } +Check-LongPathSupport + # Lower-case the passed in OS string. if ($os) { $os = $os.ToLowerInvariant() From 88ad642afa1a5a9ff7a3698cb38ad79638b907ed Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Mon, 13 Apr 2026 19:16:43 +0200 Subject: [PATCH 2/3] Update eng/build.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- eng/build.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eng/build.ps1 b/eng/build.ps1 index fe0dd135e9a34b..9bb22bf5f63eac 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -149,8 +149,9 @@ function Check-LongPathSupport() { New-Item -ItemType Directory -Path $testDir -Force | Out-Null } - # Build a file path that exceeds the 260-character MAX_PATH limit. - $basePath = Join-Path $testDir "longpath_test_" + # Build a unique file path that exceeds the 260-character MAX_PATH limit. + $uniqueSuffix = "{0}_{1}" -f $PID, ([Guid]::NewGuid().ToString("N")) + $basePath = Join-Path $testDir ("longpath_test_{0}_" -f $uniqueSuffix) $padLength = [Math]::Max(32, 270 - $basePath.Length) $testPath = $basePath + ("a" * $padLength) + ".tmp" From 22a149d2bc69cd99d413a747153f3c8e5fbdf471 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 13 Apr 2026 23:45:01 +0200 Subject: [PATCH 3/3] feedback --- eng/build.ps1 | 54 +++++++++++++++------------------------------------ 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/eng/build.ps1 b/eng/build.ps1 index 9bb22bf5f63eac..e01d1b9ecdcaee 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -136,48 +136,26 @@ function Get-Help() { } function Check-LongPathSupport() { - $repoRoot = Split-Path $PSScriptRoot -Parent - $artifactsDir = Join-Path $repoRoot "artifacts" - $stampFile = Join-Path $artifactsDir ".long-path-validated" + $regValue = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -ErrorAction SilentlyContinue - if (Test-Path $stampFile) { + if ($regValue -and $regValue.LongPathsEnabled -eq 1) { return } - $testDir = Join-Path $artifactsDir "tmp" - if (-not (Test-Path $testDir)) { - New-Item -ItemType Directory -Path $testDir -Force | Out-Null - } - - # Build a unique file path that exceeds the 260-character MAX_PATH limit. - $uniqueSuffix = "{0}_{1}" -f $PID, ([Guid]::NewGuid().ToString("N")) - $basePath = Join-Path $testDir ("longpath_test_{0}_" -f $uniqueSuffix) - $padLength = [Math]::Max(32, 270 - $basePath.Length) - $testPath = $basePath + ("a" * $padLength) + ".tmp" - - try { - [System.IO.File]::WriteAllText($testPath, "test") - Remove-Item $testPath -Force -ErrorAction SilentlyContinue - } - catch { - Write-Host "" - Write-Host "ERROR: Long file paths are not enabled on this system." -ForegroundColor Red - Write-Host "The dotnet/runtime repository requires long path support to build successfully." -ForegroundColor Red - Write-Host "" - Write-Host "Please follow the instructions at:" -ForegroundColor Yellow - Write-Host " docs\workflow\requirements\windows-requirements.md#enable-long-paths" -ForegroundColor Yellow - Write-Host "" - Write-Host "Quick fix:" -ForegroundColor Yellow - Write-Host " 1. Enable long paths in Windows (requires admin):" -ForegroundColor White - Write-Host " https://learn.microsoft.com/windows/win32/fileio/maximum-file-path-limitation" -ForegroundColor White - Write-Host " 2. Enable long paths in Git:" -ForegroundColor White - Write-Host " git config --system core.longpaths true" -ForegroundColor White - Write-Host "" - exit 1 - } - - # Validation passed - stamp so we skip this check on subsequent builds. - [System.IO.File]::WriteAllText($stampFile, "Long path support validated on $(Get-Date)") + Write-Host "" + Write-Host "ERROR: Long file paths are not enabled on this system." -ForegroundColor Red + Write-Host "The dotnet/runtime repository requires long path support to build successfully." -ForegroundColor Red + Write-Host "" + Write-Host "Please follow the instructions at:" -ForegroundColor Yellow + Write-Host " docs\workflow\requirements\windows-requirements.md#enable-long-paths" -ForegroundColor Yellow + Write-Host "" + Write-Host "Quick fix:" -ForegroundColor Yellow + Write-Host " 1. Enable long paths in Windows (requires admin):" -ForegroundColor White + Write-Host " https://learn.microsoft.com/windows/win32/fileio/maximum-file-path-limitation" -ForegroundColor White + Write-Host " 2. Enable long paths in Git:" -ForegroundColor White + Write-Host " git config --system core.longpaths true" -ForegroundColor White + Write-Host "" + exit 1 } if ($help) {