A Swiss Army knife for developers.
C# blazorcross-platformcsharpdesktopdesktop-appdesktop-applicationdeveloper-toolsextensiblefluentfluent-designlinuxmacosmicasyntax-highlightingtypescriptwindowswindows-10windows-11winui
Detect LongPath enabled on Windows (#1168)
Etienne Baudoux9e465afec4c1
diff --git a/init.ps1 b/init.ps1index e0567d4ea..22fcf9249 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 .NETExecSafe { & $PSScriptRoot\tools\Install-DotNet.ps1 -RootFolder $PSScriptRoot }diff --git a/src/Directory.Build.targets b/src/Directory.Build.targetsindex 2026e8c1d..33c0e98ac 100644--- a/src/Directory.Build.targets+++ b/src/Directory.Build.targets@@ -1,4 +1,15 @@<?xml version="1.0" encoding="utf-8"?><Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">+ <Target Name="_DevToysLongPathEnabled"+ BeforeTargets="CoreCompile"+ Condition="'$([MSBuild]::IsOsPlatform(Windows))' and '$(MSBuildThisFileDirectory.Length)' > 25">+ <!---+ Validation for LongPath support (source https://github.com/dotnet/roslyn/blob/c8eecdb9563127988b3cb564a493eae9ef254a88/eng/build.ps1#L607)+ https://docs.microsoft.com/en-us/archive/blogs/jeremykuhne/net-4-6-2-and-long-paths-on-windows-10#enabling-win32-long-path-support+ -->+ <Warning+ Condition="'$(registry:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem@LongPathsEnabled)'!='1'"+ Text="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"/>+ </Target></Project>diff --git a/tools/enable-long-paths.reg b/tools/enable-long-paths.regnew file mode 100644index 000000000..1630c48b5--- /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