diff --git a/Directory.Build.targets b/Directory.Build.targets
index 2eac9d649fa..aad3194fb6b 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -21,7 +21,7 @@
$(NoWarn);Nullable
-
+
diff --git a/docs/contributing/BuildFromSource.md b/docs/contributing/BuildFromSource.md
index f335c673aee..8ea11d49f09 100644
--- a/docs/contributing/BuildFromSource.md
+++ b/docs/contributing/BuildFromSource.md
@@ -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.
+- [LongPaths](LongPaths.md) to be enabled
### macOS/Linux
@@ -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.
diff --git a/docs/contributing/LongPaths.md b/docs/contributing/LongPaths.md
new file mode 100644
index 00000000000..7db78d9292a
--- /dev/null
+++ b/docs/contributing/LongPaths.md
@@ -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
diff --git a/eng/enable-long-paths.reg b/eng/enable-long-paths.reg
new file mode 100644
index 00000000000..a49f4aae6c1
--- /dev/null
+++ b/eng/enable-long-paths.reg
@@ -0,0 +1,4 @@
+Windows Registry Editor Version 5.00
+
+[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
+"LongPathsEnabled"=dword:00000001
diff --git a/eng/targets/Common.targets b/eng/targets/Common.targets
new file mode 100644
index 00000000000..9330efecd44
--- /dev/null
+++ b/eng/targets/Common.targets
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+ <_RazorLongPathsEnabled>$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\FileSystem', 'LongPathsEnabled', null, RegistryView.Registry64, RegistryView.Registry32))
+
+
+
+
+
\ No newline at end of file