44

I'm having trouble while building my WPF solution. Everytime I try to build it, I get this error message:

Unknown build error, 'The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.'

Someone can help me? I've already verified all the fields and their extension paths are ok. Can this be a problem with the TortoiseSVN or something like this? I recently added a folder to my solution, can be something with this?

1

8 Answers 8

33

This is a well-known restriction in the Windows win32 api. The directory in which you stored your project is nested too deep. The full path name of a file cannot contain more than 259 characters. Beyond this, lots of C code that uses MAX_PATH starts failing due to buffer overflows.

Move your solution to another directory, one that's closer to the root.

2
  • 14
    Is there any way to avoid that MAX_PATH?
    – Sonhja
    May 14, 2013 at 10:22
  • worked for me, also happens when the folder name where the solution is stored its too long. Thanks! Apr 27, 2018 at 15:31
27

I had a similar issue where the compiler reported that there was a problem with the file ASPNETCOMPILER. The actual issue was that the solution contained a node_modules folder, and this folder can contain very lengthy paths, and it looks like the compiler can't handle this.

Windows 8.1 and 10 have an option to increase the Win32 path limit:

  • Open Group Policy Editor (Press Windows+R and type gpedit.msc and hit Enter)
  • From the Group Policy Editor window, navigate to the following node: Local Computer Policy\Computer Configuration\Administrative Templates\System\Filesystem
  • Doubleclick on Enable Win32 long paths option and enable it.

This may allow you to temporarily move the problem folder out of the build, which may allow you to successfully build, then you may be able to add the folder back into the solution without affecting anything.

See here for additional reference - https://www.microfocus.com/documentation/filr/filr-4/filr-desktop/t47bx2ogpfz7.html

5
  • There is no FileSystem folder under System on my Home edition of Windows 10? Mar 12, 2018 at 23:04
  • 1
    Yes, it isn't a filepath. Open group policy editor as I've described in the first bullet point, and it'll provide a folder structure that you can navigate (it doesn't match the Windows folder structure). I'll change my answer to make this clear. Mar 13, 2018 at 4:19
  • This should be the accepted solution on windows 10 and server 16+.
    – Rouse02
    Mar 3, 2020 at 16:16
  • 1
    gpedit is only available on Windows 10 Professional and Enterprise. And besides that it appears that neither version of Visual Studio 2019 (Community, Professional, Enterprise) are actually supporting long paths even though you enable it in Windows...
    – Pieterjan
    Sep 27, 2020 at 11:27
  • 1
    You can add this link for Reference: microfocus.com/documentation/filr/filr-4/filr-desktop/…
    – Hamed Lohi
    Dec 7, 2021 at 4:05
20

There is registry approach which can be used at least for Windows 10:
Value of the parameter HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled (Type: REG_DWORD) should be set to 1. enter image description here You don't even need top restart anything (IDE or PC).

3
  • 3
    This did not work for me. I enabled Long paths using the Group Policy editor, and verified this registry key is set to 1, and still Visual Studio 2017 continues to complain about the length of my paths :-(
    – Dave.Haku
    May 21, 2021 at 4:48
  • @Dave.Haku did you try reboot? If so I'm our of ideas
    – SerjG
    May 21, 2021 at 16:50
  • Group Policy is enforced over any registry changes. So if a user's policy has it disabled, it won't matter if you reboot or not as GPO policy gets enforced at boot-up. Oct 13, 2022 at 3:46
9

This problem is caused by the restriction of Windows OS about handling long path greater than length 260. The solution of this problem for VS2019 is pretty straight-forward. But, for VS2017 users, we can use a workaround to solve the problem.

VS 2019

  • Open run window (windows-key + r), then type regedit and hit enter.
  • On the address bar of Registry Editor, enter this: HKLM\SYSTEM\CurrentControlSet\Control\FileSystem
  • On the right side, find the key LongPathsEnabled, double click on it, and change the value from 0 to 1
  • Restart VS2019, clean (if needed) and build your project again. The error should be fixed.

General workaround (VS2017/VS2019)

We can create a link of the original longer path to a shorter one. Then, VS will treat the shorter path as project root and the issue will be solved.

  • Create a shorter root path for project, e.g. we have created "D:\project" directory
  • Now open cmd (Command Prompt) and Create a symbolic link using this command: mklink /D "D:\project\myProject" "YOUR_ACTUAL_LONG_PATH_PROJECT_ROOT_DIRECTORY" [You may need to open cmd as administrator if above command fails to execute]
  • Now, open VS project from the "D:\project\myProject" directory and it should work.
3

No worry....This error comes because of long path name,Suppose your project folder name is "myproject".

You Just Change location of project folder...Put your Project "myproject" to D:\myproject or or F:\myproject drive.Then You Publish again..Its work...

Happy Coding...

1
  • wont this break any relative references?
    – JacobIRR
    Nov 1, 2021 at 21:10
1

It is issue with build defination workspace "Build Agent Folder location" VS adds paths example: $(SourceDir)E:\Somedirectory\ProjectName\ Just keep $(SourceDir) in filed

1

I had the same problem. My checkout path was shorter than the path used on my CI server. It built OK on the CI server, and all my colleagues machines. Our paths are the same length because our company has fixed length user names. I was the only machine that could not build the solution due to long paths.

If you go to these folders:

C:\Windows\Microsoft.NET\Framework

C:\Windows\Microsoft.NET\Framework64

C:\Users\[UserName]\AppData\Local\Temp

Find the version of .NET you are using with your solution, then delete the "Temporary ASP.NET Files" folders from which ever versions you think are effecting your build.

You can delete them all, your next build of a web project might take a little bit longer as there will be no pre-compiled assemblies...

This solution worked for me on a solution containing ASP.NET projects - it wont work on WPF projects that others have mentioned in their answers, unless their solution also contains ASP.NET projects.

Searching for the error string VS gives you brought me here, so I figured it might help someone else, if not the Op with a WPF build issue.

If these fail - you can try searching your solution root recursively for files/folders with paths that are greater the 260, by performing the following:

  • Open Powershell

  • cd <path to solution root>

  • cmd /c dir /s /b |? {$_.length -gt 260} > output.txt

This will pipe a list of files with paths > 260 to the output.txt file which will be newly created in the root of your solution.

This will help you find files within your solution that are too long.

1

For this, you have to run Power Shell on Windows as an administrator, and then type:

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

This solved the issue

1
  • Users must be aware of GPO enforcement. If your PC has the "Enable Win32 long paths" set to "Disabled", then your registry change will be overwritten at reboot or the next cycle of GPO enforcement. Oct 13, 2022 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.