fix: unbreak the Debug build of the Blazor demo (fixes CodeQL on dev) - #106
Conversation
Demo.BlazorWasm referenced Microsoft.DotNet.HotReload.WebAssembly.Browser
explicitly. The Blazor WebAssembly SDK already injects that package itself for
Debug builds, so the asset was contributed twice and GenerateWasmBootJson threw
on the duplicate:
Microsoft.NET.Sdk.WebAssembly.Browser.targets(395,5): error :
System.ArgumentException: An item with the same key has already been added.
Key: .../bin/Debug/net10.0/wwwroot/_framework/
Microsoft.DotNet.HotReload.WebAssembly.Browser.<hash>.wasm
Release builds never inject the hot-reload asset, so CI - which builds Release
only - stayed green and the break was invisible there. CodeQL's autobuild
builds Debug, which is why code scanning failed on dev while every CI run
passed. The reported symptom, "we were unable to automatically build your code,
switch to manual build mode", was autobuild's generic message rather than a
CodeQL configuration problem; no code-scanning change is needed.
Dropping the explicit reference leaves the SDK to supply and version the
package, as it does for every other Blazor WebAssembly app. Hot reload under
`dotnet watch` is unaffected.
Verified: the solution builds clean in BOTH configurations - Debug 0 errors
(it previously failed) and Release 0 errors (unchanged).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1b1d193 to
daaa174
Compare
|
Force-pushed a corrected branch. The previous push was wrong: I ran The branch is now rebuilt from current Re-verified on the new base (which now includes #105): Separately worth knowing: any local build dirties those 175 generated doc files on a machine whose encoding differs from whoever last committed them. That is a trap for every contributor, not just this PR. Worth either gitignoring the generated output, generating it only in CI, or pinning the encoding — happy to open a separate issue. |
The reported symptom was misleading
CodeQL reported:
That is autobuild's generic message, and it sent us toward reconfiguring code scanning. The actual cause is a real build break in this repository:
No CodeQL configuration change is needed. Default setup is fine.
Why it hid for so long
Demo.BlazorWasmreferencedMicrosoft.DotNet.HotReload.WebAssembly.Browserexplicitly, and the Blazor WebAssembly SDK already injects that package itself for Debug builds. The asset gets contributed twice andGenerateWasmBootJsonthrows on the duplicate key.Release builds never inject the hot-reload asset — so:
Demo.BlazorWasmCI builds
--configuration Releaseand stayed green throughout. CodeQL's autobuild builds Debug. That is the entire discrepancy, and it is also whydevshows a red CodeQL run while every CI run is green.The fix
Drop the explicit
PackageReference(and the now-unreferencedPackageVersion), leaving the SDK to supply and version the package — which is what it does for every other Blazor WebAssembly app. Hot reload underdotnet watchis unaffected.Two lines removed.
Verification
Reproduced locally first (identical
ArgumentExceptionon the same MSBuild target), then confirmed fixed in both configurations:Worth noting the gap this exposes: CI only ever builds Release, so a Debug-only break reaches the default branch unnoticed. Adding a Debug leg to the CI matrix would have caught this — happy to do that separately if you want it.
🤖 Generated with Claude Code