dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.22k stars 1.35k forks source link

Unable to publish Blazor app because path length #6149

Closed astrowalker closed 2 years ago

astrowalker commented 3 years ago

This is repost of report against Blazor: https://github.com/dotnet/aspnetcore/issues/30067

Describe the bug

I have Blazor web client project which I can run OK both from Visual Studio 2019 (16.8.4) and from command line. Now I would like to publish this project into local folder (I used the defaults -- "bin\Release\net5.0\browser-wasm\publish\"). When I hit Publish I got this output:

C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(237,5): Warning MSB3026: Could not copy "C:\Users\macias.nuget\packages\microsoft.aspnetcore.components.webassembly.authentication\5.0.3\staticwebassets\AuthenticationService.js" to "D:\temp\Xxxxxxx\Aaa-AAA\PpppppppppppOooooo\Xxxxxxx.Yyyyyy.Zzzzzzzzzzzzzzzzzz\Xxxxxxx.Yyyyyy.Zzzzzzzzzzzzzzzzzz.WebBlazor\Client\obj\Release\net5.0\browser-wasm\PubTmp\Out\wwwroot_content\Microsoft.AspNetCore.Components.WebAssembly.Authentication\AuthenticationService.js". Beginning retry 1 in 1000ms. Could not find a part of the path 'D:\temp\Xxxxxxx\Aaa-AAA\PpppppppppppOooooo\Xxxxxxx.Yyyyyy.Zzzzzzzzzzzzzzzzzz\Xxxxxxx.Yyyyyy.Zzzzzzzzzzzzzzzzzz.WebBlazor\Client\obj\Release\net5.0\browser-wasm\PubTmp\Out\wwwroot_content\Microsoft.AspNetCore.Components.WebAssembly.Authentication\AuthenticationService.js'.

The source file exists, the destination directory exists. I can copy the file manually, no problem.

When I copy the file myself first, and then try to publish I got extra error first stating

C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk.Publish\targets\CopyTargets\Microsoft.NET.Sdk.Publish.CopyFiles.targets(50,5): Warning MSB3231: Unable to remove directory "D:\temp\Xxxxxxx\Aaa-AAA\PpppppppppppOooooo\Xxxxxxx.Yyyyyy.Zzzzzzzzzzzzzzzzzz\Xxxxxxx.Yyyyyy.Zzzzzzzzzzzzzzzzzz.WebBlazor\Client\obj\Release\net5.0\browser-wasm\PubTmp\Out\". Could not find a part of the path 'AuthenticationService.js'.

To Reproduce

Create example Blazor app located in flat/short directory, like d:\test. This will work.

Create example Blazor app located in somewhat longer path (as above). This will work initially, but then just install nuget package to web client project "Microsoft.AspNetCore.Components.WebAssembly.Authentication" and this will tip over the path limit -- this won't work (i.e. you will not be able to publish web client).

Issues found

I see here several issues which I think should be addressed:

Further technical details

ASP.NET 5.0

PM> dotnet --info .NET SDK (reflecting any global.json): Version: 5.0.102 Commit: 71365b4d42

Runtime Environment: OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.102\

Host (useful for support): Version: 5.0.2 Commit: cb5f173b96

.NET SDKs installed: 2.1.104 [C:\Program Files\dotnet\sdk] 2.1.201 [C:\Program Files\dotnet\sdk] 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.402 [C:\Program Files\dotnet\sdk] 2.1.403 [C:\Program Files\dotnet\sdk] 2.1.504 [C:\Program Files\dotnet\sdk] 2.1.509 [C:\Program Files\dotnet\sdk] 2.1.513 [C:\Program Files\dotnet\sdk] 2.1.602 [C:\Program Files\dotnet\sdk] 2.2.104 [C:\Program Files\dotnet\sdk] 5.0.101 [C:\Program Files\dotnet\sdk] 5.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Forgind commented 3 years ago

https://github.com/dotnet/msbuild/issues/53#issuecomment-459062618

It isn't perfect, but I think that's the best we can offer. MSBuild supports long paths, but not all the tools around it do.

astrowalker commented 3 years ago

@Forgind , "the best"? The prefix of the path is "\obj\Release\net5.0\browser-wasm\PubTmp\Out", from top of my head "\obj\Release\net5.0\wasm\" -- here, it is shorter making more space for the user.

Secondly, the message is really also "the best"? I would say "Cannot use path XYZ because it exceeds the limit of ABC characters" is way more useful.

Forgind commented 3 years ago

Closing this was probably premature. We can improve the error experience (possibly just adding a catch in Copy.cs, though I would've thought this would do it) here, but I don't think we can change the path.

djthegr8 commented 3 years ago

I think that along with MSBuild, this is a fundamental problem in (probably) .NET or maybe System.IO, as I'm frequently getting System.IO.FileNotFoundException in cases where the exception should've ideally been PathTooLong, for example in the screenshot attached. image Maybe this is a bug upstream?

MikkelChristensen3Shape commented 3 years ago

Closing this was probably premature. We can improve the error experience (possibly just adding a catch in Copy.cs, though I would've thought this would do it) here, but I don't think we can change the path.

Who can change the path? dotnet/aspnetcore refused to do anything about this and redirected the OP to you.

Forgind commented 2 years ago

I made a project along the lines you suggested:

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.0-rc.2.21480.10" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.0-rc.2.21480.10" PrivateAssets="all" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.0-rc.2.21480.10" />
  </ItemGroup>

</Project>

...which is here: "C:\Users\forgind1\Folders\Archives\Bug-specific\6149\folderwithalongnameboooooooooooooooooooooooooooooooooomfolderwithalongnameboooooooooooooooooooooooooooooooooomfolderwithalongnameboooooooooooooooooooooooooooooooooom\folderrrrrrrrrrrrrrrr.csproj"

I tried dotnet publish from there, and it succeeded. Did I do some part of that wrong?

I think that along with MSBuild, this is a fundamental problem in (probably) .NET or maybe System.IO, as I'm frequently getting System.IO.FileNotFoundException in cases where the exception should've ideally been PathTooLong, for example in the screenshot attached. image Maybe this is a bug upstream?

Does that FileNotFoundException have an inner exception? That might explain why the PathTooLongException in the catch didn't trigger and would suggest an easy way to correct that part of the bug, that is, an easy way to switch the displayed exception to "Path was too long" instead of just failing to copy it.

Who can change the path? dotnet/aspnetcore refused to do anything about this and redirected the OP to you.

I don't think dotnet/aspnetcore properly looked at it, from the conversation. I'm guilty of the same, having initially thought this was a generic long paths problem. I think they're the ones who can make the path shorter or at least provide a way to opt into that behavior—that doesn't have anything to do with MSBuild, as far as I know.

ghost commented 2 years ago

This issue is marked as stale because feedback has been requested for 30 days with no response. Please respond within 14 days or this issue will be closed due to inactivity.

ghost commented 2 years ago

This issue was closed due to inactivity. If you can still reproduce this bug, please comment with the requested information, detailed steps to reproduce the problem, or any other notes that might help in the investigation.