Conversation
When multiple Blazor WASM client projects are hosted by a single server, both clients define the same HotReload JS module as a static web asset. This causes a duplicate key error in FilterStaticWebAssetEndpoints. Root cause: The ShouldIncludeAssetAsReference filter logic did not exclude CurrentProject assets when the source project uses ProjectMode=Root (which is the case for standalone Blazor WASM apps). Fix: 1. Mark the HotReload JS module with AssetMode=CurrentProject in Sdk.targets 2. Fix the filter logic to always exclude CurrentProject assets when providing assets as a reference, regardless of the source project's mode Fixes the test: Publish_HostingMultipleBlazorWebApps_Works
|
Thanks for your PR, @@lewing. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a duplicate key error in FilterStaticWebAssetEndpoints that occurs when multiple Blazor WASM client projects are hosted by a single server. The issue was caused by the HotReload JS module asset being incorrectly included as a reference asset when it should only be used by the current project.
Changes:
- Added
AssetMode="CurrentProject"to the HotReload JS module asset definition to mark it as current-project-only - Fixed the
ShouldIncludeAssetAsReferencemethod to always excludeCurrentProjectassets when providing assets as references, regardless of project mode
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/WasmSdk/Sdk/Sdk.targets | Added AssetMode="CurrentProject" attribute to the HotReload JS module asset to prevent it from flowing to consuming projects |
| src/StaticWebAssetsSdk/Tasks/Data/StaticAssetsManifest.cs | Fixed the boolean logic in ShouldIncludeAssetAsReference to always exclude CurrentProject assets when providing assets as references |
Removed unnecessary HelixCorrelationPayload entry for shipping packages.
|
@tmat please take a look |
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\BuiltInTools\HotReloadAgent.WebAssembly.Browser\Microsoft.DotNet.HotReload.WebAssembly.Browser.csproj"> |
There was a problem hiding this comment.
Should this have <ReferenceOutputAssembly>false</ReferenceOutputAssembly>?
There was a problem hiding this comment.
You'd also want to avoid flowing the current project TFM to the target project like so:
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<UndefineProperties>TargetFramework;TargetFrameworks</UndefineProperties>
If you also set
<OutputItemType>AdditionalContent</OutputItemType>
<Pack>true</Pack>
<PackagePath>hotreload</PackagePath>
you should be able to remove <AdditionalContent Include="$(ArtifactsBinDir)\Microsoft.DotNet.HotReload.WebAssembly.Browser\$(Configuration)\**\*.*"> below.
The ProjectReference should create this item.
See https://github.com/dotnet/sdk/blob/main/src/BuiltInTools/Watch/RuntimeDependencies.props#L5 for an example.
There was a problem hiding this comment.
The build is failing because of this:
src\WasmSdk\Tasks\Microsoft.NET.Sdk.WebAssembly.Tasks.csproj(0,0): error NU1201: (NETCORE_ENGINEERING_TELEMETRY=Restore) Project Microsoft.DotNet.HotReload.WebAssembly.Browser is not compatible with net472 (.NETFramework,Version=v4.7.2).
…atibility Address @tmat's review: add SkipGetTargetFrameworkProperties, ReferenceOutputAssembly=false, UndefineProperties to avoid TFM negotiation with the net472 target. Use OutputItemType=AdditionalContent to replace the separate AdditionalContent glob, following the pattern from RuntimeDependencies.props.
…et10.0 Two issues introduced by review feedback commits: 1. OutputItemType=AdditionalContent on ProjectReference doesn't flow PackagePath metadata to the created items (confirmed by @maraf in PR dotnet#52710). Restored the explicit AdditionalContent glob from that was working in the green commit. 2. HotReload csproj TFM changed from net10.0 to but Sdk.targets hardcodes _WasmHotReloadTfm=net10.0. Per @tmat's guidance in PR dotnet#52710: pin to net10.0 until higher version needed. The ProjectReference still has SkipGetTargetFrameworkProperties, ReferenceOutputAssembly=false, and UndefineProperties for net472 compatibility as @tmat requested.
|
Reverted the last two review-feedback commits ( 1. The Restored the explicit 2. TFM needs to stay pinned to Kept the |
|
/backport to release/11.0-preview1 |
|
Started backporting to |
|
@lewing an error occurred while backporting to |
|
/backport to /release/11.0.1xx-preview1 |
|
Started backporting to |
|
/backport to release/11.0.1xx-preview1 |
|
Started backporting to |
|
@lewing an error occurred while backporting to |
|
@lewing backporting to git am output$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix test assets
Applying: Remove dependency on Package for running tests
Applying: Embed HotReload in WasmSDK
Applying: Reference embedded HotReload
Applying: Define SWA for JSInitializer
Applying: Fix content root
Applying: Don't pack the package
Applying: More properties
Applying: Feedback
Applying: Copy JS part through project reference
Applying: Fix
Applying: ProjectReference with manual asset copy
Applying: Fix
Applying: Fix
Applying: Refactor
Applying: Baselines
Applying: Don't add .nuget as package source
Using index info to reconstruct a base tree...
M build/RunTestsOnHelix.cmd
M build/RunTestsOnHelix.sh
Falling back to patching base and 3-way merge...
Auto-merging build/RunTestsOnHelix.cmd
CONFLICT (content): Merge conflict in build/RunTestsOnHelix.cmd
Auto-merging build/RunTestsOnHelix.sh
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0017 Don't add .nuget as package source
Error: The process '/usr/bin/git' failed with exit code 128 |
Co-authored-by: Marek Fišera <mara@neptuo.com>
Co-authored-by: Marek Fišera <mara@neptuo.com>
The code was using:
<_WasmHotReloadModule OriginalItemSpec="%(Identity)" />
This creates a new empty item instead of setting metadata on the existing item.
Fixed to use proper MSBuild Update syntax:
<_WasmHotReloadModule Update="@(_WasmHotReloadModule)">
<OriginalItemSpec>%(Identity)</OriginalItemSpec>
</_WasmHotReloadModule>
This issue was introduced in #52816 and could cause DefineStaticWebAssets
to receive empty items, leading to potential build failures or incorrect
static web asset processing.
An extension of #52710
Summary
This PR fixes the duplicate key error in
FilterStaticWebAssetEndpointsthat occurs when multiple Blazor WASM client projects are hosted by a single server.Root Cause
When multiple Blazor WASM clients (e.g., FirstClient and SecondClient) are referenced by a host server project, both clients define the same HotReload JS module (
Microsoft.DotNet.HotReload.WebAssembly.Browser.lib.module.js) as a static web asset. Since both reference the same SDK file path, they have identical Identity values, causing a duplicate key error.Fix
Following the established pattern used by JSModules, ScopedCss, and ServiceWorker targets:
$(IntermediateOutputPath)hotreload\before being defined as a StaticWebAssetThis follows @javiercn's guidance: "What we do in other situations with assets like this is to copy them to the intermediate output folder before defining them."
Testing
The
Publish_HostingMultipleBlazorWebApps_Workstest now passes.cc @javiercn @maraf