dotnet / dotnet/aspnetcore

Experimental Microsoft.AspNetCore.ClientAssets doesn't work with .NET 9 SDK

Open
#62,925 1 comment 0 reactions 0 assignees View on GitHub
area-blazor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Using Microsoft.AspNetCore.ClientAssets on a RCL doesn't work with the .NET 9 SDK even if i target net8.0 on pack.

While ClientAssets are outputting files (correctly in my opinion) im getting the following error:

1. Create net8.0 RCL without wwwroot
2. Add Microsoft.AspNetCore.ClientAssets
3. Pack fails now

```
Restore complete (0,2s)
MyProject failed with 1 error(s) (4,2s) → bin\Release\net8.0\MyProject.dll
C:\Program Files\dotnet\sdk\9.0.303\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5019: File not found: 'D:\MyProject\obj\Release\net8.0\staticwebassets\msbuild.MyProject.Microsoft.AspNetCore.StaticWebAssetEndpoints.props'.
```

You can workaround this issue in net8.0 target framework projects by adding one single file (ive just added an empty file underscore without content "_"). Because net8 is not yet using the new StaticAssets pipeline this would work

---------

By doing the same as above while targeting net9.0 this will not work anymore (and fails on build instead of later in pack)

```
StaticAssetsClientAssets failed with 1 error(s) and 1 warning(s) (5,8s)
C:\Program Files\dotnet\sdk\9.0.303\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.Compression.targets(248,5): warning : Endpoints not found for related asset: D:\MyProject\obj\Debug\net9.0\clientassets\hello.js
C:\Program Files\dotnet\sdk\9.0.303\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.Compression.targets(248,5): error MSB4018:
The "ApplyCompressionNegotiation" task failed unexpectedly.
System.InvalidOperationException: Endpoints not found for related asset: D:\MyProject\obj\Debug\net9.0\clientassets\hello.js
at Microsoft.AspNetCore.StaticWebAssets.Tasks.ApplyCompressionNegotiation.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
```

---------

This happened because we upgraded our .NET SDK on the build machine to the newest release (both 8 & 9) i cannot exactly say which version switch caused the issue.

This could also be an issue with the .NET SDK but because Microsoft.AspNetCore.ClientAssets is experimental im placing this issue here.

We could switch to an alternative. But as far as i know we are still waiting for #38445

### Expected Behavior

We need a way to still use webpack to build our assets and include them in the RCL. (Without building them manually and copying to wwwroot)

### Steps To Reproduce

You can find a sample here:

https://github.com/dp-sgr/StaticAssetsClientAssetsIssue

### Exceptions (if any)

_No response_

### .NET Version

9.0.303

### Anything else?

Installed SDK's:
8.0.412
9.0.303

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.