Skip to content

Unify browser tools forwarding and activation for .NET 11 - #56080

Closed
javiercn wants to merge 4 commits into
javiercn-mvc-taghelper-browser-toolsfrom
javiercn-unify-browser-tools-forwarder
Closed

javiercn wants to merge 4 commits into
javiercn-mvc-taghelper-browser-toolsfrom
javiercn-unify-browser-tools-forwarder

Conversation

@javiercn

@javiercn javiercn commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Dependency

Stacked on and depends on #56072. Review this PR relative to javiercn-mvc-taghelper-browser-tools; it contains only the unified forwarding, rationalization, and watch-only activation layer.

Summary

  • Moves modern browser-tools HTTP/WebSocket endpoints, browser protocol state, scripts, and generation-scoped replay ownership into dotnet watch.
  • Adds a fixed-route, loopback-only shared-framework HTTP/WebSocket forwarder for .NET 11+ server-hosted web apps; no YARP dependency is added to applications.
  • Uses model-specific activation with one provider-hosted browser client: MVC/Razor Pages use ITagHelperComponent, Blazor Web uses a build-only afterWebStarted initializer, and standalone WASM uses its runtime initializer.
  • Passes reserved DotNetWatchBuild and DotNetWatchBrowserTools properties through watch graph evaluation, real builds, and MSBuild-based restart commands. Reserved values override user properties case-insensitively; property-incompatible commands such as format are unchanged.
  • Gives the net11 WASM initializer a watch-only asset identity. Plain dotnet run still loads the normal build-only initializer but no longer probes session.json, eliminating the inactive 404.
  • Uses the modern model for hosted WASM only when both client and server target .NET 11+; .NET 8-10 and mixed hosted combinations retain the isolated legacy path.
  • Preserves the separate DeltaApplier startup hook for managed server updates and restart recovery when the app-side forwarding connection is interrupted.

Retained compatibility boundary

The legacy implementation remains only for demonstrated consumers: pre-.NET 11 MVC/Razor Pages and generic browser refresh, older or mixed-TFM hosted WASM, and legacy blazor-hotreload clients. Those paths retain response rewriting, legacy scripts/endpoints, boot headers, WebSocket endpoint/key configuration, and virtual-directory behavior. Unsupported custom/static HTML still requires user-provided activation; no index.html rewrite is introduced.

The watch-only Web and WASM initializer selection starts at net11. Net8/net9 receive no implicit WASM Hot Reload initializer, net10 retains the normal initializer plus legacy BrowserRefresh activation, and plain/publish outputs do not contain the new Web initializer.

Final manual validation

All scenarios used artifacts\bin\redist\Debug\dotnet\dotnet.exe from external real-app directories after build.cmd -nobl completed with 0 warnings and 0 errors.

.NET 11 Blazor Web SSR

Command:

dotnet.exe watch --project .\Net11BlazorSsrManual.csproj --non-interactive /p:dotnetwatchbuild=false /p:dotnetwatchbrowsertools=false -- --urls http://127.0.0.1:5317

The deliberately lower-cased false user properties were overridden by the reserved watch values. The browser loaded exactly one fingerprinted Microsoft.NET.Sdk.Web.DotNetWatch.*.lib.module.js; session.json returned 200; the provider client connected; and a Razor heading edit rendered SSR reserved properties active after the watch log reported C# and Razor changes applied in 1896ms without restart.

dotnet.exe run --project .\Net11BlazorSsrManual.csproj -- --urls http://127.0.0.1:5317 loaded no watch initializer, made no browser-tools request, and did not connect. A watch run with DOTNET_WATCH_SUPPRESS_BROWSER_REFRESH=1 likewise loaded no initializer/client.

.NET 11 standalone Gateway WASM

Command:

dotnet.exe watch --project .\GatewayHotReloadApp.csproj --non-interactive -- --urls http://127.0.0.1:5318

The browser loaded exactly one fingerprinted .Watch.*.lib.module.js; session.json returned 200; the Gateway/YARP log showed provider HTTP forwarding and a 101 WebSocket upgrade; and a Razor edit rendered Watch filename signal validated! after C# and Razor changes applied in 1663ms without restart.

dotnet.exe run --project .\GatewayHotReloadApp.csproj -- --urls http://127.0.0.1:5318 loaded only the normal initializer identity. In a fresh browser tab it made zero dotnet-browser-tools requests and remained disconnected, confirming the inactive session.json 404 is gone.

.NET 10 standalone WASM compatibility

Command:

dotnet.exe watch --project .\net10-standalone-wasm-manual.csproj --non-interactive -- --urls http://127.0.0.1:5319

The browser loaded exactly one aspnetcore-browser-refresh.js and the normal WASM initializer, made zero modern provider requests, and stayed off the modern connection sentinel. A Razor edit rendered NET10 LEGACY PATH REVALIDATED after C# and Razor changes applied in 1771ms without restart.

Restart-style command compatibility

dotnet.exe watch --project .\Net11BlazorSsrManual.csproj --non-interactive format --no-restore --verify-no-changes

format completed and entered the normal wait-for-change state; it did not receive unsupported -p: arguments or report an unrecognized option.

Earlier manual validation on this PR also covered real net8/net9/net10 Razor Pages, net11 MVC/Razor Pages, net11 hosted WASM managed update/replay/CSS, standalone Gateway WASM HTTP/WebSocket forwarding, legacy hosted WASM, PathBase, HTTPS/WSS, multiple pages, restart recovery, cache clearing, and inactive plain dotnet run.

Manual-environment-only adjustments in those earlier scenarios: unavailable rc.1 WASM pack versions were overridden to locally available preview.7 packs; installed ASP.NET Core 8.0.30, 9.0.19, and 10.0.11 runtime folders were copied into the redist layout for real older-TFM runs. The final validation above required only alternate unused ports. No credential-provider or product workaround was used.

Automated validation

  • build.cmd -nobl — succeeded with 0 warnings and 0 errors.
  • Focused dotnet-watch.Tests property/build/format coverage — 41 passed.
  • JsModulesIntegrationTest.DotNetWatchBrowserToolsInitializer_IsWatchOnlyAndBuildOnly — 1 passed.
  • WasmJsModulesIntegrationTests.Build_UsesWatchInitializerOnlyForNet11BrowserToolsBuilds — 5 passed across net8, net9, net10, net11 plain, and net11 watch rows, asserting exactly one appropriate initializer identity.
  • Earlier focused BrowserRefresh middleware/TagHelper/forwarder/hosting-startup coverage — 55 passed.
  • Earlier focused app-model and launch-strategy coverage, including explicit net8/net9/net10/net11 and mixed hosted-TFM rows — 28 passed.
  • Final independent incremental code review found no high-confidence issues.

Design notes

  • Provider endpoints, shared secrets, DOTNET_MODIFIABLE_ASSEMBLIES, and __ASPNETCORE_BROWSER_TOOLS remain runtime launch configuration and are not embedded as build-time dynamic values.
  • Modern server launches still include the BrowserRefresh assembly in DOTNET_STARTUP_HOOKS only so the out-of-app hosting-startup assembly can be resolved. Its startup hook is a no-op in modern mode; the separate DeltaApplier startup hook remains active for managed server updates.
  • The Web initializer is a build-only net11+ static web asset and is excluded from publish. The WASM implementation remains one source module; only its asset identity changes for net11 watch builds.

@javiercn
javiercn requested review from a team, lbussell, mthalman and tmat as code owners September 1, 2026 18:25
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Move net11 server-hosted browser tooling onto the watch-owned protocol through a fixed loopback HTTP/WebSocket forwarder, including hosted WASM when both sides target net11.

Behavior: changed: modern server-hosted applications share provider-owned scripts, state, replay, and connection protocol

State: builds; regression coverage follows in the next commit

Review hint: verify the fixed destination/route, WebSocket subprotocol forwarding, and explicit TFM selection; legacy hosting startup remains isolated

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a13c60-1d66-4321-bfdb-01275ead89d6
Cover HTTP and WebSocket forwarding, provider-hosted resources, reconnect behavior, and explicit net8/net9/net10/net11 and mixed hosted-WASM launch strategies.

Behavior: preserved

State: complete for modern forwarding and compatibility selection

Review hint: the net8-net10 and mixed hosted-WASM rows prove that only all-net11 hosted applications select the provider path

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a13c60-1d66-4321-bfdb-01275ead89d6
Stop publishing the provider-hosted client as an application static asset, remove the obsolete legacy-injection switch and test-only launch facade, and reduce launch features to the managed-hot-reload decision.

Behavior: preserved: required pre-net11 and mixed hosted-WASM legacy paths remain selected and functional

State: complete

Review hint: the large baseline deletions are the removed static client asset; the client source remains embedded in and served by dotnet watch

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a13c60-1d66-4321-bfdb-01275ead89d6
@javiercn
javiercn force-pushed the javiercn-unify-browser-tools-forwarder branch from 31a1b74 to b132702 Compare September 2, 2026 10:32
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a13c60-1d66-4321-bfdb-01275ead89d6
Copilot AI lite review requested due to automatic review settings September 3, 2026 13:15
@javiercn
javiercn requested review from a team and vijayrkn as code owners September 3, 2026 13:15
@javiercn javiercn changed the title Unify browser tools forwarding for .NET 11 Unify browser tools forwarding and activation for .NET 11 Sep 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The review found concrete correctness/reliability issues (notably MSBuild FileWrites tracking in WASM targets and unbounded waiting in the test browser) that should be addressed before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR moves the modern “browser tools” (HTTP/WebSocket endpoints, protocol state, and JS client delivery) into dotnet watch for .NET 11+, adds a shared-framework forwarder for server-hosted apps, and wires watch-only activation via reserved MSBuild properties.

Changes:

  • Add a loopback-only HTTP/WebSocket forwarding path (BrowserToolsForwarder) and model-specific activation for modern browser tools under dotnet watch.
  • Flow reserved DotNetWatchBuild / DotNetWatchBrowserTools properties through watch evaluation and “real” build/restart command invocations.
  • Update WASM/Web static web assets + baselines/tests to reflect watch-only initializer identity and provider-hosted client modules.
File summaries
File Description
test/Microsoft.NET.Sdk.StaticWebAssets.Tests/JsModulesIntegrationTest.cs Adds regression test ensuring the Web initializer is watch/build-only and excluded from publish output.
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmJsModulesIntegrationTests.cs Adds matrix test for net8–net11 ensuring only net11 watch builds use the watch-only initializer identity.
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/StaticWebAssets_BuildMinimal_Works.Build.staticwebassets.json Updates baseline to remove the BrowserTools JS module from the app asset graph.
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/StaticWebAssets_BuildMinimal_Works.Build.files.json Updates baseline file list to match new WASM asset outputs.
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/StaticWebAssets_Build_Hosted_Works.Build.staticwebassets.json Updates hosted baseline to remove BrowserTools module assets/endpoints.
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/JSModules_ManifestIncludesModuleTargetPaths.Build.staticwebassets.json Updates baseline to remove BrowserTools module entries/endpoints.
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/StaticWebAssetsBaselines/Build_DoesNotGenerateManifestJson_IncludesJSModulesOnBlazorBootJsonManifest.Build.staticwebassets.json Updates baseline to remove BrowserTools module entries/endpoints.
test/Microsoft.Extensions.DotNetDeltaApplier.Tests/BrowserToolsEndpointRouterTests.cs Adds coverage for provider-served JS module endpoints.
test/Microsoft.AspNetCore.Watch.BrowserRefresh.Tests/HostingStartupTest.cs Updates assertions for “modern provider configured” vs legacy-only wiring.
test/Microsoft.AspNetCore.Watch.BrowserRefresh.Tests/BrowserToolsForwarderTest.cs New forwarder tests validating HTTP and WebSocket forwarding semantics.
test/Microsoft.AspNetCore.Watch.BrowserRefresh.Tests/BrowserRefreshTagHelperComponentTest.cs Updates TagHelper activation to load the modern bootstrap module.
test/Microsoft.AspNetCore.Watch.BrowserRefresh.Tests/BrowserRefreshMiddlewareTest.cs Removes legacy “disable injection” parameterization and updates middleware construction.
test/dotnet-watch.Tests/Watch/NoRestoreTests.cs Updates process-argument assertions to account for reserved watch properties being inserted.
test/dotnet-watch.Tests/HotReload/BuildProjectsTests.cs Updates expected build/restore invocations to include reserved watch properties.
test/dotnet-watch.Tests/CommandLine/SubcommandTests.cs Verifies watch’s MSBuild evaluation command line includes reserved properties.
test/dotnet-watch.Tests/Build/EvaluationResultTests.cs Adds test verifying reserved property override behavior (case-insensitive).
test/dotnet-watch.Tests/Browser/BrowserRefreshServerTests.cs Updates environment configurator expectations and adds forwarding configurator coverage.
test/dotnet-watch.Tests/Browser/BlazorWebAssemblyAppModelTests.cs Updates app-model selection tests for modern vs legacy launch strategies (including mixed TFMs).
test/dotnet-watch-test-browser/Program.cs Updates test browser to prefer modern session.json/connect and optionally reconnect via application forwarding.
src/WebSdk/Web/Targets/Sdk.Server.targets Adds net11+ build-only Web initializer when DotNetWatchBrowserTools=true.
src/WebSdk/Web/Targets/DotNetWatch/Microsoft.NET.Sdk.Web.DotNetWatch.lib.module.js New afterWebStarted module importing the provider bootstrap when needed.
src/WasmSdk/Sdk/Sdk.targets Switches WASM initializer identity to watch-only for net11 watch builds and removes BrowserTools module from the app asset graph.
src/Dotnet.Watch/Web.Middleware/StartupHook.cs Makes BrowserRefresh startup hook a no-op when modern provider forwarding is active.
src/Dotnet.Watch/Web.Middleware/HostingStartup.cs Registers forwarder + TagHelper activation when provider address is configured; legacy path remains for pre-net11/compat.
src/Dotnet.Watch/Web.Middleware/BrowserToolsForwarderOptions.cs New options record for configuring the forwarder provider address.
src/Dotnet.Watch/Web.Middleware/BrowserToolsForwarder.cs New loopback-only HTTP/WebSocket forwarder implementation.
src/Dotnet.Watch/Web.Middleware/BrowserToolsEnvironment.cs Adds provider address parsing/validation for modern forwarding activation.
src/Dotnet.Watch/Web.Middleware/BrowserRefreshTagHelperComponent.cs Switches injected activation script to the modern bootstrap module.
src/Dotnet.Watch/Web.Middleware/BrowserRefreshMiddleware.cs Removes legacy injection toggle; legacy rewrite path is now always enabled when this middleware runs.
src/Dotnet.Watch/Web.Middleware/ApplicationPaths.cs Adds modern fixed route constants for /_framework/dotnet-browser-tools.
src/Dotnet.Watch/Watch/HotReload/HotReloadDotNetWatcher.cs Ensures reserved watch properties are passed through MSBuild-based restart builds.
src/Dotnet.Watch/Watch/Build/EvaluationResult.cs Ensures reserved watch properties are always set for design-time evaluation properties.
src/Dotnet.Watch/Watch/Build/BuildUtilities.cs Adds case-insensitive build-property parsing into an immutable dictionary.
src/Dotnet.Watch/Watch/Build/BuildNames.cs Introduces reserved property name constants for watch flow.
src/Dotnet.Watch/Watch/AppModels/WebApplicationAppModel.cs Selects forwarding vs legacy launch configurator based on .NET 11+ support and adjusts WebSocket hostname behavior.
src/Dotnet.Watch/Watch/AppModels/BlazorWebAssemblyHostedAppModel.cs Uses modern path only when both client and server TFMs are .NET 11+; otherwise keeps legacy behavior.
src/Dotnet.Watch/Watch/AppModels/BlazorWebAssemblyAppModel.cs Uses Gateway proxy launch configurator for net11+ standalone WASM; otherwise uses legacy hosting-startup path.
src/Dotnet.Watch/HotReloadClient/Web/WebSocketConfig.cs Adds WithHostName helper used to force loopback hostname for modern provider mode.
src/Dotnet.Watch/HotReloadClient/Web/MiddlewareEnvironmentVariables.cs Replaces legacy HTML injection env var with provider-address env var constant.
src/Dotnet.Watch/HotReloadClient/Web/IBrowserToolsLaunchConfigurator.cs Removes BrowserToolsLaunchFeatures flags enum in favor of explicit configurator selection.
src/Dotnet.Watch/HotReloadClient/Web/HostingStartupBrowserToolsLaunchConfigurator.cs Switches to explicit enableManagedHotReload boolean and removes legacy HTML injection env-var emission.
src/Dotnet.Watch/HotReloadClient/Web/ForwardingBrowserToolsLaunchConfigurator.cs New configurator emitting provider-address + activation via hosting-startup assembly resolution.
src/Dotnet.Watch/HotReloadClient/Web/BrowserToolsProtocol.cs Adds new paths for provider-served client + bootstrap modules.
src/Dotnet.Watch/HotReloadClient/Web/BrowserToolsEndpointRouter.cs Adds endpoints serving the provider-hosted browser client and bootstrap modules from embedded resources.
src/Dotnet.Watch/HotReloadClient/Web/AbstractBrowserRefreshServer.cs Removes old “configure env” helper; caller now selects configurator explicitly.
src/Dotnet.Watch/HotReloadClient/Microsoft.DotNet.HotReload.Client.projitems Embeds the browser-tools client JS module as an assembly resource for provider serving.
src/Dotnet.Watch/HotReloadAgent.WebAssembly.Browser/wwwroot/Microsoft.DotNet.HotReload.WebAssembly.BrowserTools.lib.module.js Expands JS module to include provider discovery and reconnect/reload behavior.
src/Dotnet.Watch/HotReloadAgent.WebAssembly.Browser/wwwroot/Microsoft.DotNet.HotReload.WebAssembly.Browser.lib.module.js Adjusts runtime initializer to use provider-hosted client and gate modern probing on watch-only identity.
src/Dotnet.Watch/dotnet-watch/Watch/MsBuildFileSetFactory.cs Ensures evaluation and watch-list generation include reserved properties.
src/Dotnet.Watch/dotnet-watch/Watch/DotNetWatcher.cs Updates environment setup to use the new launch configurator signature.
src/Dotnet.Watch/dotnet-watch/Watch/BuildEvaluator.cs Inserts reserved properties into supported subcommands before application arguments (--).
src/Dotnet.Watch/AGENTS.md Updates contributor guidance for modern provider/forwarder ownership and activation behavior.
eng/Signing.props Removes signing entry for BrowserTools JS module now served from embedded resource/provider.
.github/memory/ARCHITECTURE.md Documents the reserved-property flow and net11+ watch-only initializer selection at a high level.
Review details
  • Files reviewed: 54/54 changed files
  • Comments generated: 3
  • Review effort level: Lite

Comment on lines +27 to +32
if (!Uri.TryCreate(value, UriKind.Absolute, out var address) ||
address.Scheme != Uri.UriSchemeHttp ||
!IsLoopbackHost(address))
{
throw new InvalidOperationException($"The configured browser tools provider address '{value}' is not a loopback HTTP address.");
}
Comment on lines 57 to 59
<FileWrites Include="$(_WasmHotReloadIntermediatePath)Microsoft.DotNet.HotReload.WebAssembly.Browser.lib.module.js" />
<FileWrites Include="$(_WasmHotReloadIntermediatePath)Microsoft.DotNet.HotReload.WebAssembly.BrowserTools.lib.module.js" />
<FileWrites Include="$(_WasmHotReloadIntermediatePath)Microsoft.DotNet.HotReload.WebAssembly.Browser.Watch.lib.module.js" />
<FileWrites Include="$(_WasmHotReloadIntermediatePath)Microsoft.DotNet.HotReload.WebAssembly.Browser.dll" />
Comment on lines +161 to +177
while (true)
{
try
{
using var response = await httpClient.GetAsync(sessionUrl);
if (response.IsSuccessStatusCode)
{
return;
}
}
catch (HttpRequestException e)
{
Console.WriteLine($"Waiting for browser tools route: {e.Message}");
}

await Task.Delay(100);
}
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Due to lack of recent activity, this PR has been labeled as 'Stale'. It will be closed if no further activity occurs within 7 more days. Any new comment will remove the label.

@github-actions github-actions Bot added the stale label Nov 2, 2026
@github-actions github-actions Bot closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants