Skip to content

Switch Blazor WebAssembly package to SWA Framework Assets and clean up custom props#65984

Open
javiercn wants to merge 7 commits intomainfrom
javiercn/cleanup-wasm-packaging
Open

Switch Blazor WebAssembly package to SWA Framework Assets and clean up custom props#65984
javiercn wants to merge 7 commits intomainfrom
javiercn/cleanup-wasm-packaging

Conversation

@javiercn
Copy link
Member

@javiercn javiercn commented Mar 26, 2026

Summary

Modernizes the Microsoft.AspNetCore.Components.WebAssembly NuGet package to use the Static Web Assets (SWA) Framework Assets system for blazor.webassembly.js, and removes the legacy BlazorRoutingEnableRegexConstraint workaround from the package props.

Changes

Microsoft.AspNetCore.Components.WebAssembly.csproj

  • Added <Sdk Name="Microsoft.NET.Sdk.StaticWebAssets" /> to enable the SWA pack pipeline (no Razor SDK needed)
  • Added StaticWebAssetFrameworkPattern (**/*.js) so the SWA pipeline marks JS files with SourceType=Framework during pack
  • Added StaticWebAssetsDisableProjectBuildPropsFileGeneration since we ship a custom props file that imports the SWA-generated props
  • Used Content Include with Link="wwwroot\_framework\blazor.webassembly.js" so DefineStaticWebAssets discovers the JS file at the correct relative path
  • Changed custom props packaging from build\$(DefaultNetCoreTargetFramework)\ to build\

Microsoft.AspNetCore.Components.WebAssembly.props

  • Removed BlazorWebAssemblyJSPath property (replaced by SWA framework asset declarations)
  • Removed BlazorRoutingEnableRegexConstraint property default and RuntimeHostConfigurationOption item (moved to SDK targets in companion PR)
  • Removed AssemblyMetadataAttribute workaround (no longer needed — Mono WASM runtime now reads configProperties from runtimeconfig.json natively)
  • Added imports for the SWA-generated Microsoft.AspNetCore.StaticWebAssets.props and Microsoft.AspNetCore.StaticWebAssetEndpoints.props

WebAssemblyHostBuilder.cs

  • Removed InitializeRoutingAppContextSwitch() method and its call — this was a workaround that read AssemblyMetadataAttribute to manually set the AppContext switch. The Mono WASM runtime now handles this natively via runtimeconfig.json configProperties.

RegexConstraintSupport.cs

  • Updated outdated comment (the AppContext switch now flows to the WASM runtime)

Components.TestServer.csproj (test asset)

  • Added RuntimeHostConfigurationOption directly (temporary, until SDK targets handle it)

How it works

  1. The SWA pack pipeline discovers blazor.webassembly.js via the Content item with Link metadata
  2. GenerateStaticWebAssetsPropsFile applies the FrameworkPattern glob and emits props declaring the asset with SourceType=Framework
  3. At consume time, UpdateExistingPackageStaticWebAssets materializes framework assets to obj/staticwebassets/fx/ automatically
  4. The SDK's _ResolveBlazorWasmOutputs target is skipped for .NET 11+ (see companion SDK PR)
  5. BlazorRoutingEnableRegexConstraint flows via RuntimeHostConfigurationOptionruntimeconfig.json → Mono WASM runtime reads configPropertiesAppContext.SetSwitch()

Companion PR

Testing

  • .NET 11 Blazor WASM app: builds successfully, framework asset materialized, runs in browser with counter interactivity verified
  • .NET 10 Blazor WASM app: builds successfully with backward-compatible BlazorWebAssemblyJSPath flow

- Change project SDK to Microsoft.NET.Sdk.Razor to enable SWA pack pipeline
- Use Content+Link to map blazor.webassembly.js into wwwroot/_framework/
- Set StaticWebAssetFrameworkPattern to mark JS as Framework SourceType
- Ship custom props at build/ (not build/tfm/) to import SWA-generated props
- Remove BlazorWebAssemblyJSPath from package props (replaced by SWA declarations)
@github-actions github-actions bot added the area-blazor Includes: Blazor, Razor Components label Mar 26, 2026
@javiercn javiercn marked this pull request as ready for review March 26, 2026 07:23
@javiercn javiercn requested a review from a team as a code owner March 26, 2026 07:23
Copilot AI review requested due to automatic review settings March 26, 2026 07:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Microsoft.AspNetCore.Components.WebAssembly NuGet package to ship blazor.webassembly.js via the Static Web Assets (SWA) Framework Assets pipeline instead of the legacy BlazorWebAssemblyJSPath mechanism.

Changes:

  • Switch the project SDK to Microsoft.NET.Sdk.Razor and enable SWA framework-asset classification for JS during packing.
  • Adjust packaging so the package’s custom props ship under build/, and blazor.webassembly.js is discovered as a static web asset via a Link under wwwroot/_framework/.
  • Update the package props to import SWA-generated props/endpoints files and remove BlazorWebAssemblyJSPath.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Components/WebAssembly/WebAssembly/src/targets/Microsoft.AspNetCore.Components.WebAssembly.props Imports SWA-generated props/endpoints and removes the legacy BlazorWebAssemblyJSPath property.
src/Components/WebAssembly/WebAssembly/src/Microsoft.AspNetCore.Components.WebAssembly.csproj Switches to Razor SDK, configures SWA framework pattern, disables project build-props generation, and updates pack/link setup for the JS asset and custom props.

The project doesn't need Razor compilation. Import only the SWA SDK
alongside Microsoft.NET.Sdk for the pack pipeline.
The Mono WASM runtime now reads configProperties from runtimeconfig.json
and applies them as AppContext switches. The AssemblyMetadataAttribute
workaround and InitializeRoutingAppContextSwitch are no longer needed.

- Strip custom props to only SWA imports
- Remove InitializeRoutingAppContextSwitch from WebAssemblyHostBuilder
- Move RuntimeHostConfigurationOption temporarily to Components.TestServer
- Update outdated comment in RegexConstraintSupport.cs
@javiercn javiercn changed the title Switch Blazor WebAssembly JS to SWA Framework Assets Switch Blazor WebAssembly package to SWA Framework Assets and clean up custom props Mar 26, 2026
The custom props file only contained SWA imports, which the SWA SDK
generates automatically. Remove StaticWebAssetsDisableProjectBuildPropsFileGeneration
and stop packing targets/*.props manually.
The targets/Microsoft.AspNetCore.Components.WebAssembly.props file is no
longer needed. The SWA SDK auto-generates the package props for NuGet
consumers. For in-repo project-reference consumers, Directory.Build.targets
already sets BlazorWebAssemblyJSPath so the SDK _ResolveBlazorWasmOutputs
target picks up the JS file from Web.JS/dist/.
The Content item with Link='wwwroot\_framework\blazor.webassembly.js'
causes DefineStaticWebAssets to resolve the file, which fails in the
No-NodeJS CI build leg where Web.JS is not built.
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

Successfully merging this pull request may close these issues.

3 participants