Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
jirisykora83 opened this issue Nov 15, 2024 · 7 comments
Open
1 task done
Labels
area-blazor Includes: Blazor, Razor Components
Milestone

Comments

@jirisykora83
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

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

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Nov 15, 2024
@Tornhoof
Copy link
Contributor

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

@jirisykora83
Copy link
Author

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
Copy link
Member

@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?

@javiercn javiercn added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Nov 15, 2024
@jirisykora83
Copy link
Author

@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

@dotnet-policy-service dotnet-policy-service bot added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Nov 15, 2024
@javiercn
Copy link
Member

@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

@javiercn javiercn added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Nov 15, 2024
@jirisykora83
Copy link
Author

@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.

@dotnet-policy-service dotnet-policy-service bot added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Nov 15, 2024
@javiercn
Copy link
Member

@jirisykora83 thanks for the additional details.

So, what's happening here is that on the initial build things work and on additional builds (after the app has run and generated additional files) those files are then considered static assets and cause the build to fail (given the issue above).

We will likely address this issue, however, even in that case, you should consider changing your approach. One way to do this is to create a .cache folder on your app at runtime, place these cache files there and serve them via app.UseStaticFiles with a custom IFileProvider.

It is best to keep your cache content separate from your static files content as they have very different lifecycles and constraints. As of .NET 9.0, a lot of build/publish time optimizations will apply to the files in the wwwroot folder, which likely don't make sense to your cache files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

4 participants