Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,16 @@
<StaticWebAssetEndpoint Include="@(_BlazorWebViewModulesFallbackEndpoint)" />
</ItemGroup>
</Target>
<!-- RCLs contribute precompressed .gz/.br copies of their assets as Alternative
static web assets. Blazor Hybrid disables compression above, but those items
still reach the publish pipeline and are copied next to the uncompressed files.
Drop them before the publish manifest and the Brotli publish pass run. -->
<Target Name="_RemoveBlazorWebViewPrecompressedAssets"
BeforeTargets="GenerateStaticWebAssetsPublishManifest;ResolvePublishStaticWebAssets;GeneratePublishCompressedStaticWebAssets"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this filtering be implemented in the shared StaticWebAssets SDK instead of only the WebView targets? With the .NET 11 SDK, a Blazor WebAssembly app with a project-referenced RCL still imports the RCL's compressed alternatives when CompressionEnabled=false; publish then contains gzip and Brotli copies. In my NuGet RCL sample, the package contained uncompressed assets and the consuming app owned compression, so it was already clean. This target addresses the Hybrid publish case but leaves the project-reference leak in other StaticWebAssets scenarios.

The shared SDK already has build and publish resolution hooks in Microsoft.NET.Sdk.StaticWebAssets.targets (publish hook). We could filter Alternative assets with the Content-Encoding trait, which the compression task assigns, and remove their endpoints using the existing filtering pattern. Build and publish need separate target names because publish runs build in the same MSBuild session. A prototype at these hooks removed the project-reference alternatives and published compressed files in the tested sample, while leaving compression-enabled output unchanged.

Note

This comment was generated with the assistance of GitHub Copilot.

Condition="'$(CompressionEnabled)' == 'false'">
Comment thread
joshbarros marked this conversation as resolved.
Resolved
<ItemGroup>
<StaticWebAsset Remove="@(StaticWebAsset)"
Comment thread
joshbarros marked this conversation as resolved.
Resolved
Condition="'%(StaticWebAsset.AssetRole)' == 'Alternative' and ('%(StaticWebAsset.Extension)' == '.gz' or '%(StaticWebAsset.Extension)' == '.br')" />
</ItemGroup>
</Target>
</Project>
Loading