Skip to content

Commit

Permalink
Move LongPath check to MSBuild target (#68217)
Browse files Browse the repository at this point in the history
The Roslyn repository effectively depends on having long paths enabled
at this point. Between NuGet and the VSSDK, both outside our control,
our repository runs right up against `MAX_PATH` limits even with a very
short user name. A user name of any significant length will quickly run
into issues in our repo.

The repository already warns about long path support, and has for some
time, but it does so in command line builds. That was a fine experience
when it was added as long path support was new and was only needed in a
few cases. Now though it's effectivtely needed for everyone so need to
give it more visibility by elevating it to an MSBuild warning.

This warning is _deliberately_ not configurable. Having long paths
disabled at this point means your inner loop dev experience is broken in
strange, hard to diagnose ways.

Co-authored-by: Jared Parsons <[email protected]>
  • Loading branch information
jaredpar and Jared Parsons authored May 30, 2023
1 parent 59727ee commit d84d54f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 0 additions & 5 deletions eng/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,6 @@ try {
exit 1
}

$regKeyProperty = Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name "LongPathsEnabled" -ErrorAction Ignore
if (($null -eq $regKeyProperty) -or ($regKeyProperty.LongPathsEnabled -ne 1)) {
Write-Host "LongPath is not enabled, you may experience build errors. You can avoid these by enabling LongPath with `"reg ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1`""
}

Process-Arguments

. (Join-Path $PSScriptRoot "build-utils.ps1")
Expand Down
4 changes: 4 additions & 0 deletions eng/enable-long-paths.reg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001
8 changes: 8 additions & 0 deletions eng/targets/Imports.targets
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@
Condition="$(_VersionComparisonResult) &lt; 0"/>
</Target>

<Target Name="_CheckLongPathSupport" BeforeTargets="BeforeBuild" Condition="'$(MSBuildRuntimeType)' == 'Full'">
<PropertyGroup>
<_RoslynLongPathsEnabled>$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\FileSystem', 'LongPathsEnabled', null, RegistryView.Registry64, RegistryView.Registry32))</_RoslynLongPathsEnabled>
</PropertyGroup>

<Warning Condition="'$(_RoslynLongPathsEnabled)' != '1'" Text="Long paths are required for this project. Please run eng\enable-long-paths.reg" />
</Target>

<!--
This target is used to copy referenced projects to a sub-directory vs. the direct output
directory of the build. Useful when the referenced project is an EXE and the referencing
Expand Down

0 comments on commit d84d54f

Please sign in to comment.