Skip to content

MSBuild should handle paths longer than MAX_PATH #53

Closed

Description

@ariccio

As seen in Fix 260 character file name length limitation, there's quite a bit of support for better longer-than-MAX_PATH-filename handling.

Will Buik's response w/regard to fixing it was:

We understand that this can be a frustrating issue, however, fixing it requires a large and complicated architectural change across different products and features including Visual Studio, TFS, MSBuild and the .NET Framework. Dedicating resources to this work item would come at the expense of many other features and innovation.

I wondered, how big can those architectural changes be (for MSBuild)?

According to Naming Files, Paths, and Namespaces: Maximum Path Length Limitation, (which I have mirrored here ):

The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters). To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path".
[other stuff]

Because you cannot use the "\\?\" prefix with a relative path, relative paths are always limited to a total of MAX_PATH characters.

(emphasis mine)

...Which means that wherever MSBuild uses full paths, we can should be able to just prepend "\\?\" to ask for a long path.

Of course, we'd need to rework the existing path-length-workaround hack.

This won't fix the whole ecosystem, but it'll get us just one step closer.

I'd like to fix this myself (it seems simple enough), so in accordance with:

  • Contributions must be discussed with the team first, or they will likely be declined. As our process matures and our experience grows, the team expects to take larger contributions.
  • Only contributions referencing an approved Issue will be accepted.

...this is the suggested issue.

I'm a native developer at heart, not an experienced C# developer, but this shouldn't require anything crazy.

Direct references to MAX_PATH:

Activity

  1. AndyGerlicher commented on Mar 31, 2015

    @AndyGerlicher
    Contributor

    MSBuild team triage: This isn't a change we're looking to take anytime soon as it would be fairly substantial with implications on dependent tasks and tools.

  2. ariccio commented on Apr 1, 2015

    @ariccio
    Author

    [...]it would be fairly substantial with implications on dependent tasks and tools.

    Could you be a bit more specific?

  3. ariccio commented on Apr 8, 2015

    @ariccio
    Author

    I'm still curious as to what the substantial implications of an incremental fix for MSBuild in isolation are, exactly.

  4. MattWhilden commented on Apr 9, 2015

    @MattWhilden

    In general, you'd have to have all of the other things you're using understand long paths. There's been a number of discussions internally and externally about the MAX_PATH issue and they always eventually boil down to: "If we could rewrite everything we'd be good but we can't so there's an infinite sea of compat risk here :-(".

    So... maybe some day?

  5. gwojan commented on Apr 9, 2015

    @gwojan

    Have you looked at AlphaFS?

  6. MattWhilden commented on Apr 9, 2015

    @MattWhilden

    The key issue here is that it doesn't really matter if MSBUILD is updated. It's not an island. it passes paths to lots of other things (OS apis, tools etc) and updating yourself in a way that doesn't break them is a Hard Problem (tm). Almost certainly not impossible but there's lots of other work with better payoffs.

  7. ariccio commented on Apr 10, 2015

    @ariccio
    Author

    Hmm. The way I see it, is that the entire toolchain is not compatible with paths longer than MAX_PATH, and thus by (incrementally) fixing a single component will not lead to toolchain-wide regression. It'll just be broken in a different place - the entire toolchain, when used as a system, will still be broken, but in a slightly smaller way.

    It's even worse, by the way, as MAX_PATH was only the "maximum total file path length" for FAT16, and pre-Unicode/pre-NT APIs. Any documentation that says MAX_PATH is the longest possible file path is horribly wrong! MAX_PATH should really have been named MAX_FAT_PATH or MAX_PATH_COMPONENT; any program that was built after Windows NT 3.1 (yes, July 27, 1993, the earliest default use of NTFS that I know of) to use Unicode APIs with the assumption that MAX_PATH is the longest possible file path is, and always was, terminally broken. GCC 4.9-style broken.

    I can even find discussions dating more than ten years back, of developers realizing that assuming MAX_PATH is the maximum length of a path is an outdated (ridiculous) assumption.

    Any components that have been retroactively "fixed" to ensure compatibility with only paths that are MAX_PATH or shorter - well, that's just crazy.

    Also, I can't imagine that we can break the OS APIs themselves by using them in a documented manner.

    So yeah, it's a Hard Problem™, and I know that we don't yet have proper time travel, but if we attack it incrementally, we either make small (and effectively non-functional) improvements, or expose bugs/unforeseen design issues in other components.

    I say effectively non-functional, because those components that can't handle MAX_PATH are already broken for paths longer than MAX_PATH. I can't imagine that those applications rely internally on the exact full path name that's given to them.

    Furthermore, I imagine that OTHER toolchains use MSBuild in ways that are crippled by the MAX_PATH limitations.

    ...and while new features/better compliance are nice, I think they're counterproductive/add silly complexity if the core components that they're built on are shaky and fail in unexpected ways (e.g. MAX_PATH limitations). Putting it off into the future only makes it harder to fix.

    Lastly, let me remind you of the nearly 3000 users who voted on "Fix 260 character file name length limitation" before it was declined. There are still users commenting on the issue with frustration.

    Here's an idea

    How about you/we go ahead and make the changes to MSBuild, make it available as a "preview" or "technology demonstration", and see what (if anything) breaks.

  8. MattWhilden commented on Apr 10, 2015

    @MattWhilden

    You seem to understand the issue pretty well. I don't disagree that isn't a frustrating experience some times but they have finite resources and can only take so much risk. I'd be more interested in them making sure cross plat is brought up cleanly but it's up to them. I'm sure they appreciate your enthusiasm and feedback. I'll bow out of this issue for now.. lots of other bugs to track down.

  9. ariccio commented on Apr 10, 2015

    @ariccio
    Author

    Fair enough.

  10. noamkfir commented on Apr 10, 2015

    @noamkfir

    @ariccio If you have the inclination, I say go for it. Everybody will eventually benefit, especially if more pieces of the toolchain go open source. Saying that it can't be fixed because everything else in every possible toolchain would also have to be fixed immediately is, quite simply, a non-starter and completely unrealistic. The whole point of going open source is to let people scratch their itches, especially when Microsoft doesn't have the resources to do it themselves...

    One way to minimize the risk associated with backwards and toolchain compatibility that Microsoft keeps talking about is to ensure that the current limitation remains the default behavior while making it possible to opt-in to longer paths. The opt-in mechanism can be via any relevant configuration mechanism, including a new command line option, a build file setting, a registry setting and/or some other mechanism.

  11. gingters commented on May 28, 2015

    @gingters

    I'm also in.

    Especially down the road to xplat, where *NIX operating systems do not care about a 260 char path length at all. IF set at all (this may well be -1 to indicate that there is no limit) it for example defaults to 4096 on x86 Linux. On OS X's HFSP the max path length is unlimited (while the file name is limited to 255).

    So, in fact, this issue here is a blocker for xplat.

    Yes, there may be other places in VS, TFS and other tools that have problems with this, but as long as we want to simply 'MSBuild mysolution' on commandline or on an CI system like AppVoyer or Travis, and happen to have paths longer than 260 chars there, it should not artificially prevent us from doing so.

    I also don't see how removing this limitation would break other stuff.
    If other stuff can't handle paths longer than 260 chars, it already IS broken. It won't break more. I would just break elsewhere.

    And: Yes. Especially because MSBuild is not an island, but a part in a chain, someone has to start. And MSBuild is the perfect place because it can be used more or less standalone on new DNX projects (because, honestly, Sake is the totally wrong thing for building stuff), and it could be the door-opener to fix the stuff in other places too. Best thing is, that others like the VS or TFS team won't have excuses like 'MSBuild doesn't support that, so why should we change that?' anymore.

    When talking about where to spent time, it's mostly the time of the community that will be spend here. So why not simply start here, by removing that artifical limitation, pass longer paths around where necessary and, who knows, maybe much less is broken that is currently being thought off and a lot of stuff simply starts to work out of the box?

  12. Piedone commented on May 28, 2015

    @Piedone
    Member

    👍

    Mediaeval issues like this still prevent us from using proper folder structures and proper file/folder names still. And it's not a corner case: for us all of our builds would fail if not copied to the drive root of the build server!

  13. hacst commented on Sep 4, 2015

    @hacst

    👍 This is something everyone with a complex build in a build system encounters sooner or later and it is quite annoying to work around. Fixing it has to start somewhere.

  14. ariccio commented on Sep 4, 2015

    @ariccio
    Author

    Glad to see that people are still voicing their support. Fixing this arcane issue is certainly not a glamorous job - hence the foot-dragging - but it's a desperately important one.

  15. 79 remaining items

  16. inf9144 commented on Apr 7, 2020

    @inf9144

    @rainersigwald could you please reopen this ticket because of the bug in 64bit?

  17. KirillOsenkov commented on Apr 7, 2020

    @KirillOsenkov
    Member

    I think this should be a new issue, with specifics about 64-bit not working as expected

  18. mahaase commented on May 4, 2020

    @mahaase

    I think this should be a new issue, with specifics about 64-bit not working as expected

    I opened a new ticket for 64-bit variant. I hope the issue will solved soon, now. This bug is a show-stopper.

  19. Piedone commented on May 4, 2020

    @Piedone
    Member

    Worth linking to it: #5331

  20. brignolij commented on Oct 14, 2020

    @brignolij

    Hi, I'm facing the issue with path limit using AWS codebuild (meaning buildspec.yml file) , msbuild and with docker image (mcr.microsoft.com/dotnet/framework/sdk, https://hub.docker.com/_/microsoft-dotnet-framework-sdk).
    Any suggestion to make it work using only powershell/cmd command ?
    more documentation :
    https://aws.amazon.com/fr/blogs/devops/creating-ci-cd-pipelines-for-asp-net-4-x-with-aws-codepipeline-and-aws-elastic-beanstalk/

  21. rainersigwald commented on Oct 14, 2020

    @rainersigwald
    Member

    @brignolij I'm sorry, I don't know whether the container hosts need the long-path configuration, or just the container images. If setting the registry key inside the container doesn't work, I think you'd have to ask AWS support.

  22. brignolij commented on Oct 15, 2020

    @brignolij

    @rainersigwald Thanks for your answer.
    I already have a issue open with AWS support, they suggest me to check on msbuild support. I have a project with long path. (lot of files ,folders). So i really want to make it work with long path.
    i test this following command into my buildsepc
    Set-ItemProperty 'HKLM:\System\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -value 1
    but this command requiere a system restart to be effective and this not possible on build system like awscodebuild.
    I'm open to any suggestion.
    Also is application manifest file required for .net framework mvc app?
    is yes where should we add ?

    <application xmlns="urn:schemas-microsoft-com:asm.v3">
        <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
            <ws2:longPathAware>true</ws2:longPathAware>
        </windowsSettings>
    </application>
    

    Regards

  23. PhDittmann commented on Mar 18, 2021

    @PhDittmann

    @rainersigwald was this expected to be fixed in both the 32bit and 64bit (amd64\msbuild.exe) msbuild binaries? I am getting interesting behavior wherein the 64 bit version throws this error:

    "S:\Builds\GenerateInterop-60R39\WorkingDirectory\src\Dotnet\Source\Framework\Interop\Project\ComputersUnlimited.Interop.sln" (Restore target) (1) ->
    (Restore target) ->
      C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(121,5): 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. [S:\Builds\GenerateInterop-60R39\WorkingDirectory\src\Dotnet\Source\Framework\Interop\Project\ComputersUnlimited.Interop.sln]
    

    Whereas using the 32bit version has no such qualms (restores and builds without issue).

    Here's the version from the 64bit and 32bit versions (same):

    Microsoft (R) Build Engine version 16.1.76+g14b0a930a7 for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.
    

    I can open a new issue if need be but wanted to start here. If this is something I need to get off to the NuGet guys I can do that as well.

    I just had the same problem.

    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe
    
    Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.
    

    fails with 'path too long' while

    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe
    
    Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.
    

    (without \amd64) works perfectly for the same .sln.

  24. matteius commented on Jul 6, 2022

    @matteius

    Ran into this issue with a report to the pipenv backlog that I triaged: pip install fastchunking on windows fails outright with this: pypa/pip#11231

    https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk1104?view=msvc-170#paths-that-are-too-long

    I have enabled the registry key for Windows 10 long paths, but the 2019 Visual Studio linker don't care about that. Is there any path of resolution other than move the temp directory to a shorter path so that hopefully the compiled file path lengths don't exceed 260?

  25. hsdk123 commented on Jun 17, 2023

    @hsdk123

    Same problem here - unsure why this was closed.

  26. rainersigwald commented on Jun 19, 2023

    @rainersigwald
    Member

    @hsdk123 please file a new bug with details of the problem you're seeing.

  27. walbourn commented on Jun 22, 2023

    @walbourn

    The current versions of MSBuild long-path aware in the manifest:

      <application xmlns="urn:schemas-microsoft-com:asm.v3">
          <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
              <ws2:longPathAware>true</ws2:longPathAware>
          </windowsSettings>
      </application>
    

    I'm not sure WHEN this was added...

  28. rainersigwald commented on Jun 22, 2023

    @rainersigwald
    Member

    @walbourn #53 (comment).

    I'm going to lock this thread, since the core issues are long fixed and anything that crops up now should get a new issue.

  29. locked as resolved and limited conversation to collaborators on Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: EngineArea: Taskstriaged

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions