Switch Blazor WebAssembly package to SWA Framework Assets and clean up custom props#65984
Open
Switch Blazor WebAssembly package to SWA Framework Assets and clean up custom props#65984
Conversation
- 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)
Contributor
There was a problem hiding this comment.
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.Razorand enable SWA framework-asset classification for JS during packing. - Adjust packaging so the package’s custom props ship under
build/, andblazor.webassembly.jsis discovered as a static web asset via aLinkunderwwwroot/_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. |
...onents/WebAssembly/WebAssembly/src/targets/Microsoft.AspNetCore.Components.WebAssembly.props
Outdated
Show resolved
Hide resolved
javiercn
commented
Mar 26, 2026
src/Components/WebAssembly/WebAssembly/src/Microsoft.AspNetCore.Components.WebAssembly.csproj
Outdated
Show resolved
Hide resolved
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Modernizes the
Microsoft.AspNetCore.Components.WebAssemblyNuGet package to use the Static Web Assets (SWA) Framework Assets system forblazor.webassembly.js, and removes the legacyBlazorRoutingEnableRegexConstraintworkaround from the package props.Changes
Microsoft.AspNetCore.Components.WebAssembly.csproj<Sdk Name="Microsoft.NET.Sdk.StaticWebAssets" />to enable the SWA pack pipeline (no Razor SDK needed)StaticWebAssetFrameworkPattern(**/*.js) so the SWA pipeline marks JS files withSourceType=Frameworkduring packStaticWebAssetsDisableProjectBuildPropsFileGenerationsince we ship a custom props file that imports the SWA-generated propsContent IncludewithLink="wwwroot\_framework\blazor.webassembly.js"soDefineStaticWebAssetsdiscovers the JS file at the correct relative pathbuild\$(DefaultNetCoreTargetFramework)\tobuild\Microsoft.AspNetCore.Components.WebAssembly.propsBlazorWebAssemblyJSPathproperty (replaced by SWA framework asset declarations)BlazorRoutingEnableRegexConstraintproperty default andRuntimeHostConfigurationOptionitem (moved to SDK targets in companion PR)AssemblyMetadataAttributeworkaround (no longer needed — Mono WASM runtime now readsconfigPropertiesfromruntimeconfig.jsonnatively)Microsoft.AspNetCore.StaticWebAssets.propsandMicrosoft.AspNetCore.StaticWebAssetEndpoints.propsWebAssemblyHostBuilder.csInitializeRoutingAppContextSwitch()method and its call — this was a workaround that readAssemblyMetadataAttributeto manually set theAppContextswitch. The Mono WASM runtime now handles this natively viaruntimeconfig.jsonconfigProperties.RegexConstraintSupport.csComponents.TestServer.csproj(test asset)RuntimeHostConfigurationOptiondirectly (temporary, until SDK targets handle it)How it works
blazor.webassembly.jsvia theContentitem withLinkmetadataGenerateStaticWebAssetsPropsFileapplies theFrameworkPatternglob and emits props declaring the asset withSourceType=FrameworkUpdateExistingPackageStaticWebAssetsmaterializes framework assets toobj/staticwebassets/fx/automatically_ResolveBlazorWasmOutputstarget is skipped for .NET 11+ (see companion SDK PR)BlazorRoutingEnableRegexConstraintflows viaRuntimeHostConfigurationOption→runtimeconfig.json→ Mono WASM runtime readsconfigProperties→AppContext.SetSwitch()Companion PR
Testing
BlazorWebAssemblyJSPathflow