dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.39k stars 10k forks source link

Blazor Service Worker Asset Manifest path construction bug #25959

Closed amis92 closed 2 years ago

amis92 commented 4 years ago

Describe the bug

When BaseIntermediateOutputPath is non-default, GenerateServiceWorkerAssetsManifest task fails.

To Reproduce

> dotnet new blazorwasm --pwa -o BlazorSwamPathBugRepro
> cd BlazorSwamPathBugRepro
> echo "<Project>
    <PropertyGroup>
        <BaseOutputPath>$(MSBuildThisFileDirectory)build/bin/$(MSBuildProjectName)/</BaseOutputPath>
        <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build/obj/$(MSBuildProjectName)/</BaseIntermediateOutputPath>
    </PropertyGroup>
</Project>" > Directory.Build.props

Repro repo: https://github.com/amis92/BlazorSwamPathBugRepro

Exceptions (if any)

Exception stack trace C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets(68,5): error MSB4018: The "GenerateServiceWorkerAssetsManifest" task failed unexpectedly. [C:\Users\Amadeusz\Source\Repos\BlazorSwamPathBugRepro\BlazorSwamPathBugRepro.csproj] C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets(68,5): error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\Amadeusz\Source\Repos\BlazorSwamPathBugRepro\obj\Debug\net5.0\service-worker-assets.js'. [C:\Users\Amadeusz\Source\Repos\BlazorSwamPathBugRepro\BlazorSwamPathBugRepro.csproj] C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets(68,5): error MSB4018: at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle) [C:\Users\Amadeusz\Source\Repos\BlazorSwamPathBugRepro\BlazorSwamPathBugRepro.csproj] C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets(68,5): error MSB4018: at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options) [C:\Users\Amadeusz\Source\Repos\BlazorSwamPathBugRepro\BlazorSwamPathBugRepro.csproj] C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets(68,5): error MSB4018: at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) [C:\Users\Amadeusz\Source\Repos\BlazorSwamPathBugRepro\BlazorSwamPathBugRepro.csproj] C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets(68,5): error MSB4018: at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) [C:\Users\Amadeusz\Source\Repos\BlazorSwamPathBugRepro\BlazorSwamPathBugRepro.csproj] C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets(68,5): error MSB4018: at System.IO.File.Create(String path) [C:\Users\Amadeusz\Source\Repos\BlazorSwamPathBugRepro\BlazorSwamPathBugRepro.csproj] C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets(68,5): error MSB4018: at Microsoft.NET.Sdk.BlazorWebAssembly.GenerateServiceWorkerAssetsManifest.Execute() [C:\Users\Amadeusz\Source\Repos\BlazorSwamPathBugRepro\BlazorSwamPathBugRepro.csproj] C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets(68,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\Amadeusz\Source\Repos\BlazorSwamPathBugRepro\BlazorSwamPathBugRepro.csproj] C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets(68,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\Users\Amadeusz\Source\Repos\BlazorSwamPathBugRepro\BlazorSwamPathBugRepro.csproj]

Further technical details

.NET SDK (reflecting any global.json):
 Version:   5.0.100-rc.1.20452.10
 Commit:    473d1b592e

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\

Host (useful for support):
  Version: 5.0.0-rc.1.20451.14
  Commit:  38017c3935

.NET SDKs installed:
  2.1.809 [C:\Program Files\dotnet\sdk]
  3.1.402 [C:\Program Files\dotnet\sdk]
  5.0.100-rc.1.20452.10 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.2 [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.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.2 [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.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-rc.1.20451.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.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.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-rc.1.20451.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0-rc.1.20452.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Personal investigation

The issue seems to crop up in Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets which is part of Microsoft.NET.Sdk.BlazorWebAssembly in this repository:

https://github.com/dotnet/aspnetcore/blob/50eb578c738bf007f0a37efcdc99ee72157b9dd1/src/Components/WebAssembly/Sdk/src/targets/Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets#L19-L21

First of all, when the BaseIntermediateOutputPath is rooted, it doesn't actually use any user-set path and instead just forces the path to be relative and arbitrary, which doesn't seem to be correct (but maybe I'm missing something):

obj\$(Configuration)\$(TargetFramework)\$(ServiceWorkerAssetsManifest)

However, the second case looks like it should work, except it doesn't seem possible for the BaseIntermediateOutputPath to not be rooted at that point, because of the following:

https://github.com/dotnet/sdk/blob/d7ee9e27927f11c7e1b8ad1f48bcbffd2ac7a000/src/WebSdk/Publish/Targets/Microsoft.NET.Sdk.Publish.targets#L74-L75

Additionally I'm concerned that the _ServiceWorkerAssetsManifestIntermediateOutputPath itself shouldn't be used at all in other targets in that file and it is (the failing task itself takes it as an input); instead the _ServiceWorkerAssetsManifestFullPath probably should be.

ghost commented 4 years ago

Thanks for contacting us. We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

ghost commented 4 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

Kylar182 commented 3 years ago

This started happening to me all the time after moving my project to 5. Cut my dev time to a total crawl.

robauer commented 3 years ago

So - I'm guessing this isn't going to fixed anytime in the near future? What is the work around for this? This halts any work I can do in Blazor.

Kylar182 commented 3 years ago

So - I'm guessing this isn't going to fixed anytime in the near future? What is the work around for this? This halts any work I can do in Blazor.

I just deleted all bin / obj folders in the project and did a clean / rebuild on the solution and it worked fine.

andreatosato commented 3 years ago

Same error here: https://github.com/andreatosato/azure-static-app-pushnotification/actions When debug work well. When build locally work well:

dotnet publish ./src/Client/Blazoring.PWA.Client.csproj -c Release -o blazor -f NET5.0

On Github action there is error!

SimonCropp commented 3 years ago

suspect related to https://github.com/dotnet/aspnetcore/issues/29939

robauer commented 3 years ago

I deleted bin and obj files, Cleaned and Build - no change. Still have same issue.

SteveSandersonMS commented 3 years ago

@javiercn Any idea if this is resolved with the 6.0 SWA updates?

javiercn commented 3 years ago

I believe so

pranavkm commented 2 years ago

@javiercn assigning this to you to unskip this test: https://github.com/dotnet/sdk/blob/main/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIntegrationTest.cs#L492 if this issue is resolved.

javiercn commented 2 years ago

@pranavkm sign-off and merge when happy? https://github.com/dotnet/sdk/pull/22463