[browser] Don't copy framework assets to output during build#126407
[browser] Don't copy framework assets to output during build#126407
Conversation
During build, the WebAssembly SDK was copying all .wasm and .js framework assets to bin/wwwroot/_framework/ via CopyToOutputDirectory=PreserveNewest. This is unnecessary because dotnet run uses the static web assets middleware, which serves files directly from their obj/ locations using the manifest. Change CopyToOutputDirectory from PreserveNewest to Never for: - Webcil-converted assets (Computed static web assets) - Materialized framework assets (dotnet.js, dotnet.native.wasm, etc.) This eliminates ~178 file copies during build while preserving correct behavior for dotnet run (static web assets middleware) and publish (CopyToPublishDirectory was already Never). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🤖 Copilot Code Review — PR #126407Note This review was generated by GitHub Copilot. Holistic AssessmentMotivation: The PR eliminates unnecessary file copies during build. The static web assets middleware serves files directly from Approach: Changing Summary: Detailed Findings❌ Documentation — Stale comment contradicts code at lines 427-432The XML comment block at lines 427-432 explicitly describes the old behavior that this PR removes: <!-- Materialized framework assets must be visible to referencing projects (e.g. Blazor WASM
hosted scenarios where the server project serves the client's framework files).
UpdatePackageStaticWebAssets defaults AssetMode to CurrentProject and CopyToOutputDirectory
to Never. Override both: AssetMode=All so assets flow through project references, and
CopyToOutputDirectory=PreserveNewest so they are copied from the intermediate materialized
path (obj/fx/{SourceId}/) to bin/wwwroot/_framework/ at build time. -->The comment says Suggested fix — update the comment to reflect the new behavior, e.g.: <!-- Materialized framework assets must be visible to referencing projects (e.g. Blazor WASM
hosted scenarios where the server project serves the client's framework files).
UpdatePackageStaticWebAssets defaults AssetMode to CurrentProject. Override AssetMode=All
so assets flow through project references. CopyToOutputDirectory stays Never because the
static web assets middleware serves files directly from obj/ locations during development. -->✅ Correctness — Build-time behavior preserved via middlewareThe static web assets middleware serves files from their ✅ Publish behavior — UnaffectedThe publish pipeline is handled separately (lines ~887-925) with 💡 Scope — Consistent change across all three asset registration sitesThe change touches the three correct locations where build-time WASM assets were configured for copying:
All three are consistently set to
|
There was a problem hiding this comment.
Pull request overview
This PR changes the WebAssembly SDK build targets to stop copying runtime/framework static web assets into bin/wwwroot/_framework during build, relying instead on the static web assets manifest/middleware to serve them from their source locations (typically under obj/ or the runtime pack).
Changes:
- Set
CopyToOutputDirectory="Never"for build-time static web assets emitted from webcil conversion (SourceType="Computed"). - Set
CopyToOutputDirectory="Never"for build-time runtime pack assets registered asSourceType="Framework". - Set
CopyToOutputDirectory="Never"for the post-UpdatePackageStaticWebAssets“materialized” framework assets (per-projectobj/fx/{SourceId}/copies).
| <!-- Materialized framework assets must be visible to referencing projects (e.g. Blazor WASM | ||
| hosted scenarios where the server project serves the client's framework files). | ||
| UpdatePackageStaticWebAssets defaults AssetMode to CurrentProject and CopyToOutputDirectory | ||
| to Never. Override both: AssetMode=All so assets flow through project references, and | ||
| CopyToOutputDirectory=PreserveNewest so they are copied from the intermediate materialized | ||
| path (obj/fx/{SourceId}/) to bin/wwwroot/_framework/ at build time. --> |
There was a problem hiding this comment.
The comment above this ItemGroup still says CopyToOutputDirectory is overridden to PreserveNewest to copy materialized framework assets into bin/wwwroot/_framework at build time, but the code now sets CopyToOutputDirectory="Never". Please update the comment to reflect the new behavior/rationale (and avoid referencing build-time copying if that is no longer intended).
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
|
Note This comment was generated with the assistance of GitHub Copilot. Blazor WASM Hosted Scenario AnalysisTesting revealed that the existing // Lines 169-179
string client1Framework = Path.Combine(client1Dir, "bin", config.ToString(),
DefaultTargetFrameworkForBlazor, "wwwroot", "_framework");
Assert.True(Directory.Exists(client1Framework), ...);
Assert.Contains(client1Files, f => Path.GetFileName(f).StartsWith("dotnet.") && f.EndsWith(".js"));This test creates two Blazor WASM client projects hosted by a single server and verifies that each client gets its own physical framework files — validating the Framework Impact Summary
Next StepsOptions to consider:
|
Note
This PR was created with the assistance of GitHub Copilot.
Summary
During build, the WebAssembly SDK copies all
.wasmand.jsframework assets (~178 files) tobin/wwwroot/_framework/viaCopyToOutputDirectory=PreserveNewest. This is unnecessary becausedotnet runuses the static web assets middleware, which serves files directly from theirobj/locations via the manifest (staticwebassets.runtime.json).Changes
Set
CopyToOutputDirectory=Never(wasPreserveNewest) for threeDefineStaticWebAssets/ item-update calls inMicrosoft.NET.Sdk.WebAssembly.Browser.targets:.wasmfiles produced from.dlldotnet.js,dotnet.native.wasm, runtime JS, etc.UpdatePackageStaticWebAssets) — the per-project copies inobj/fx/Validation
dotnet buildwithTargetOS=browser)dotnet runstarts WasmAppHost dev server correctly42)bin/wwwroot/_framework/drops from ~178 files to 2 (only hot-reload module + dotnet.js from a separate code path)CopyToPublishDirectorywas alreadyNever— publish is unaffectedNotes
PreserveNewestwas added for Blazor WASM hosted scenarios where a server project serves the client's framework files. This scenario needs separate validation.obj/dirs), so physical copies inbin/are not needed fordotnet run.