diff --git a/init.ps1 b/init.ps1 index e0567d4ea1..22fcf92496 100755 --- a/init.ps1 +++ b/init.ps1 @@ -6,6 +6,13 @@ function ExecSafe([scriptblock] $cmd) { Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { Write-Error $_ -ErrorAction Continue; exit 1 } $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent +# Verify LongPath is enabled +# Forked from https://github.com/dotnet/roslyn/blob/c8eecdb9563127988b3cb564a493eae9ef254a88/eng/build.ps1#L607 +$regKeyProperty = Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name "LongPathsEnabled" -ErrorAction Ignore +if (($null -eq $regKeyProperty) -or ($regKeyProperty.LongPathsEnabled -ne 1)) { + Write-Host -ForegroundColor Yellow "Warning: LongPath is not enabled, you may experience build errors. You can avoid these by enabling LongPath. You can enable it by running `"tools/enable-long-paths.reg`". More information on https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell#enable-long-paths-in-windows-10-version-1607-and-later" +} + # Install .NET ExecSafe { & $PSScriptRoot\tools\Install-DotNet.ps1 -RootFolder $PSScriptRoot } diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets index 2026e8c1d6..33c0e98aca 100644 --- a/src/Directory.Build.targets +++ b/src/Directory.Build.targets @@ -1,4 +1,15 @@ + + + + diff --git a/tools/enable-long-paths.reg b/tools/enable-long-paths.reg new file mode 100644 index 0000000000..1630c48b52 --- /dev/null +++ b/tools/enable-long-paths.reg @@ -0,0 +1,4 @@ +Windows Registry Editor Version 5.00 + +[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem] +"LongPathsEnabled"=dword:00000001 \ No newline at end of file