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.49k stars 10.04k forks source link

MSB4018: The "DefineStaticWebAssetEndpoints" task failed unexpectedly. #58975

Open jirisykora83 opened 1 day ago

jirisykora83 commented 1 day ago

Is there an existing issue for this?

Describe the bug

New StaticWebAssets make build fail. Mostly likely because of weird file names.

1>C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: The "DefineStaticWebAssetEndpoints" task failed unexpectedly. 1>C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: System.IO.FileNotFoundException: Could not find file 'wwwroot\images\7474b9fd-5ab7-4c37-83ad-5e954a8cc7fb\Grünerløkka--w1920_jpg.webp'. 1>C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: File name: 'wwwroot\images\7474b9fd-5ab7-4c37-83ad-5e954a8cc7fb\Grünerløkka--w1920_jpg.webp' 1>C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 1>C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at System.IO.FileInfo.get_Length() 1>C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssetEndpoints.GetFileLength(StaticWebAsset asset) 1>C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssetEndpoints.CreateEndpoints(StaticWebAsset asset, ContentTypeProvider contentTypeMappings) 1>C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at Microsoft.AspNetCore.StaticWebAssets.Tasks.DefineStaticWebAssetEndpoints.Execute() 1>C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() 1>C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(675,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

Is there any option to disable new StaticWebAssets for specific folder (in this case it is just "cache" as images are loaded from API and store in wwwroot). It should be an issue, just for dev build (i guess - not ready to deploy).

Even if the option for excluding folder exists, I still think this should not happen.

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

9.0.100

Anything else?

No response

Tornhoof commented 1 day ago

What happens if you remove (for testing) the file with the non-ascii file name? (\Grünerløkka--w1920_jpg.webp)

jirisykora83 commented 1 day ago

Then it works. I already removed all of them. Annoying is that it stops on first (not sure if it is default or my VS settings) so cleaning them manually is not fun :/

javiercn commented 1 day ago

@jirisykora83 thanks for contacting us.

We'll take a look, in the mean time, you can exclude those files from the Content item group and that should let things go through.

If you have a repro project that will definitely help.

Additionally, is there any tool that you are using to generate those files?

jirisykora83 commented 1 day ago

@jirisykora83 thanks for contacting us.

We'll take a look, in the mean time, you can exclude those files from the Content item group and that should let things go through.

If you have a repro project that will definitely help.

Additionally, is there any tool that you are using to generate those files?

No, it just caches files in wwwroot during runtime as this works well (no need to download again as it is semi-expensive operation). Deployed app use CDN but localhost not.

For replication i try to isolate the issue as much as possible.

https://github.com/jirisykora83/BlazorApp3

Image

javiercn commented 1 day ago

@jirisykora83 thanks for the additional details.

So, to make sure that we understand, you are generating some cache files at runtime and placing them inside the wwwroot folder (with the idea that they can be served as assets at that point?) or does that cache gets populated as part of the build?

I imagine that what we need to do here is percent encode the url

jirisykora83 commented 1 day ago

@jirisykora83 thanks for the additional details.

So, to make sure that we understand, you are generating some cache files at runtime and placing them inside the wwwroot folder (with the idea that they can be served as assets at that point?) or does that cache gets populated as part of the build?

I imagine that what we need to do here is percent encode the url

Yes exactly. Error then happens during local build when app previously runs (download some files).

-- "I imagine that what we need to do here is percent encode the url"

I'm not sure about this because if the file is not in the folder it may work. Maybe the issue is not about the file name itself but the whole path. I am not sure.