This issue started as a report about an issue (#4) with SpawnDev.BlazorJS.WebWorkers but the issue may actually lie in a .Net 9 SDK build task.
Repo: WebWorkers.Issue4
The .Net 9 Blazor WASM compression build task, ApplyCompressionNegotiation
, fails due to an unknown issue handling Razor Class Library Nuget packages that use <StaticWebAssetBasePath>/</StaticWebAssetBasePath>
when referenced by another Razor Class Library
- Quick Start - fastest way to see the issue and a possible workaround
- Steps To Reproduce From Scratch - create projects from scratch
- Repo Demo Projects - uses this repo and demo Nuget project
How to demo the issue with this repo WebWorkers.Issue4: To see the issue:
- Clone repo
- Run
_publish.bat
inWebWorkers.Issue4
folder to do a Releasepublish
build The "ApplyCompressionNegotiation" task failed unexpectedly ...
Test workaround 1:
- Uncomment
<CompressionEnabled>false</CompressionEnabled>
inRazorClassLibrary1.csproj
- Run
_publish.bat
inWebWorkers.Issue4
folder to do a Releasepublish
build Build succeeded
Test workaround 2:
- Remove
net9.0
from<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
inRazorClassLibrary1.csproj
- Run
_publish.bat
inWebWorkers.Issue4
folder to do a Releasepublish
build Build succeeded
- Create a solution with a .Net 9 Razor Class Library (RCL) and set
<StaticWebAssetBasePath>/</StaticWebAssetBasePath>
in its.csproj
. - Publish the RCL as a Nuget package (publishing locally is fine)
- Create a new solution with an .Net 9 Razor Class Library and a .Net 9 Blazor WASM
- In the RCL, PackageReference to the Nuget package from step 2 (a ProjectReference does not trigger the bug)
- In the Blazor WASM app add a ProjectReference to the RCL project in the same solution
- Run
dotnet publish --nologo --configuration Release --output bin\Publish
in the Blazor WASM app folder to see the error.
You get an exception similar to:
D:\users\tj\Projects\Issue4\WebWorkers.Issue4\WebWorkers.Issue4>dotnet publish --nologo --configuration Release --output "D:\users\tj\Projects\Issue4\WebWorkers.Issue4\WebWorkers.Issue4\bin\Publish\"
Restore complete (0.5s)
RazorClassLibrary1 net9.0 succeeded (3.3s) → D:\users\tj\Projects\Issue4\WebWorkers.Issue4\RazorClassLibrary1\bin\Release\net9.0\RazorClassLibrary1.dll
RazorClassLibrary1 net9.0 succeeded (0.1s) → D:\users\tj\Projects\Issue4\WebWorkers.Issue4\RazorClassLibrary1\bin\Release\net9.0\RazorClassLibrary1.dll
WebWorkers.Issue4 failed with 1 error(s) and 1 warning(s) (0.6s)
C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.Compression.targets(323,5): warning : Endpoints not found for compressed asset: example.JsInterop.faux.js.gz D:\users\tj\Projects\Issue4\WebWorkers.Issue4\WebWorkers.Issue4\obj\Release\net9.0\compressed\87ntuufp02-gq62o8712c.gz
C:\Program Files\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.Compression.targets(323,5): error MSB4018:
The "ApplyCompressionNegotiation" task failed unexpectedly.
System.InvalidOperationException: Endpoints not found for compressed asset: D:\users\tj\Projects\Issue4\WebWorkers
.Issue4\WebWorkers.Issue4\obj\Release\net9.0\compressed\87ntuufp02-gq62o8712c.gz
at Microsoft.AspNetCore.StaticWebAssets.Tasks.ApplyCompressionNegotiation.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLogging
Context taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
WebWorkers.Issue4 failed (9.7s) → bin\Release\net9.0\wwwroot
Build failed with 1 error(s) and 1 warning(s) in 15.4s
- Workaround: Disable compression (
<CompressionEnabled>false</CompressionEnabled>
) in the 2nd solution's Razor Class Library's.csproj
and the publish will succeed and all static web assets will compress normally.
The projects in this repo demonstrate this bug.
The .Net 9 Blazor WASM project WebWorkers.Issue4
references the RCL project RazorClassLibrary1
and has compression enabled with <CompressionEnabled>true</CompressionEnabled>
(default if omitted.)
RazorClassLibrary1
is a Razor Class Library that references any Nuget package RCL that uses <StaticWebAssetBasePath>/</StaticWebAssetBasePath>
.
This can be a Nuget packaged RazorClassLibrary2
, but it must be a PackageReference
not a ProjectReference
. Alternatively it can be SpawnDev.BlazorJS.WebWorkers
version 2.5.22
.
RazorClassLibrary2
is a minimal Razor Class Library to demonstrate the issue. It is a bare RCL that uses <StaticWebAssetBasePath>/</StaticWebAssetBasePath>
. It needs to be packaged as a Nuget package and that package (not the project) must be referenced by RazorClassLibrary1
.
To demonstrate the bug without requiring creating a Nuget package using RazorClassLibrary2
, the package <PackageReference Include="SpawnDev.BlazorJS.WebWorkers" Version="2.5.22" />
(which uses <StaticWebAssetBasePath>/</StaticWebAssetBasePath>
) can be referenced by RazorClassLibrary1
.
Run dotnet publish --nologo --configuration Release --output bin\Publish
in the WebWorkers.Issue4
folder to see the error.
Disable compression (<CompressionEnabled>false</CompressionEnabled>
) in RazorClassLibrary1.csproj
and the publish will succeed and all static web assets will compress normally.
If you get the error Endpoints not found for compressed asset
during a Blazor publish
build, a possible fix is to modify your Razor Class Library's .csproj
:
<PropertyGroup>
<CompressionEnabled>false</CompressionEnabled>
</PropertyGroup>
It does not affect, or disable compression of any part of the Blazor app, but it does prevent the Endpoints not found for compressed asset
error.
This issue does not exist in .Net 8 or earlier.