Skip to content

Commit

Permalink
dx: warn about long paths disabled (#11140)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzngard authored Dec 4, 2024
2 parents 8f3c0a8 + b3759d6 commit 14238b2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<NoWarn>$(NoWarn);Nullable</NoWarn>
</PropertyGroup>

<Import Project="eng\targets\Packaging.targets" />
<Import Project="eng\targets\Common.targets" />

<!-- Workaround https://github.com/dotnet/cli/issues/10528 -->
<PropertyGroup>
Expand Down
7 changes: 1 addition & 6 deletions docs/contributing/BuildFromSource.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Building Razor on Windows requires:
- Windows 10, version 1803 or newer
- At least 10 GB of disk space and a good internet connection (our build scripts download a lot of tools and dependencies)
- Git. <https://git-scm.org>
- [LongPaths](LongPaths.md) to be enabled

### macOS/Linux

Expand Down Expand Up @@ -69,12 +70,6 @@ Before opening the `Razor.sln` file in Visual Studio or VS Code, you need to per
of Razor to be deployed. This can be useful if the latest Razor bits depend on a breaking change in
Roslyn that isn't available in the version of Visual Studio being targeted. If you encounter errors
when debugging the Razor bits that you've built and deployed, setting this switch _might_ fix them.
> :bulb: Windows tip: if you encounter errors pointing to `path-too-long` errors, like `The fully qualified file name must be less than 260 characters.`, consider shortening your local path with `subst`, where `R` is a free drive-letter, e.g.
>> ```ps1
>> $dir = pwd
>> subst R: $dir
>> cd R:\
>> ```

3. Set `Microsoft.VisualStudio.RazorExtension` as the startup project.

Expand Down
39 changes: 39 additions & 0 deletions docs/contributing/LongPaths.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Handling long paths on windows

This repository requires [windows long paths support] to be enabled.

## Git
In order to clone sucessfully, you might need to allow for [git long paths]:
```shell
git config --global core.longpaths true
```

## Building
While working with the project, you might encounter load- or buildtime-errors popping up, hinting on paths being too long on your local environment, f.e.:
```
error MSB4248: Cannot expand metadata in expression "$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))".
The item metadata "%(FullPath)" cannot be applied to the path "TestFiles\IntegrationTests\ComponentDesignTimeCodeGenerationTest\GenericComponent_GenericEventCallbackWithGenericTypeParameter_NestedTypeInference\TestComponent.mappings.txt".
Path: {{REPOSITORY_ROOT}}\src\Compiler\Microsoft.AspNetCore.Razor.Language\test\TestFiles\IntegrationTests\ComponentDesignTimeCodeGenerationTest\GenericComponent_GenericEventCallbackWithGenericTypeParameter_NestedTypeInference\TestComponent.mappings.txt exceeds the OS max path limit. The fully qualified file name must be less than 260 characters.
```

or similar.

This repository also generates a warning when building on windows and long paths are not enabled:
```
error LongPathsDisabled: Long paths are required for this project. See 'docs/contributing/LongPaths.md' on how to overcome this.
```

To overcome this, apply one of the following options:

### Enable long path support
> :bulb: This is the preferred approach of the razor team
Either import / execute [/eng/enable-long-path.reg] or invoke the following powershell-script from an elevated prompt:

```ps1
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value "1" -PropertyType DWORD -Force
```

[git long paths]:https://stackoverflow.com/questions/22575662/filename-too-long-in-git-for-windows
[windows long paths support]:https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later
[/eng/enable-long-path.reg]:../../eng/enable-long-paths.reg
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
16 changes: 16 additions & 0 deletions eng/targets/Common.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<Import Project="Packaging.targets" />

<Target Name="_CheckLongPathSupport" BeforeTargets="BeforeBuild;CollectPackageReferences" Condition="'$(MSBuildRuntimeType)' == 'Full'">
<PropertyGroup>
<_RazorLongPathsEnabled>$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\FileSystem', 'LongPathsEnabled', null, RegistryView.Registry64, RegistryView.Registry32))</_RazorLongPathsEnabled>
</PropertyGroup>
<Warning Condition="'$(_RazorLongPathsEnabled)' != '1'"
Code="LongPathsDisabled"
Text="Long paths are required for this project. See 'docs/contributing/LongPaths.md'"
HelpLink="https://github.com/dotnet/razor/blob/main/docs/contributing/LongPaths.md"
/>
</Target>

</Project>

0 comments on commit 14238b2

Please sign in to comment.