Skip to content

Browser refresh server cleanup and .NET Framework impl - #56568

Merged
tmat merged 14 commits into
dotnet:mainfrom
tmat:dev/tomat/browser-refresh-cleanup
Oct 13, 2026
Merged

tmat merged 14 commits into
dotnet:mainfrom
tmat:dev/tomat/browser-refresh-cleanup

Conversation

@tmat

@tmat tmat commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Follow up on #56118.

Simplifies Browser Refresh Server implementation and adds .NET Framework implementation with functionality on par with Kestrel.

The .NET Framework implementation is needed for VS.

Best to review commit by commit.

@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.

@tmat tmat changed the title Move environment configuration back to AbstractBrowserRefreshServer Browser refresh server cleanup Oct 9, 2026
@tmat
tmat force-pushed the dev/tomat/browser-refresh-cleanup branch from 3af1569 to fe34b7f Compare October 10, 2026 15:17
@tmat tmat changed the title Browser refresh server cleanup Browser refresh server cleanup and .NET Framework impl Oct 10, 2026
@tmat
tmat marked this pull request as ready for review October 10, 2026 23:54
@tmat
tmat requested a review from a team as a code owner October 10, 2026 23:54
Copilot AI balanced review requested due to automatic review settings October 10, 2026 23:54
@tmat

tmat commented Oct 10, 2026 •

Copy link
Copy Markdown
Member Author

@javiercn @dotnet/hot-reload ptal

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 .NET Framework listener cannot start with its generated prefixes and has blocking disposal and request-serialization defects.

3 open findings
What changed in this PR

Consolidates browser-refresh hosting and adds a .NET Framework HttpListener implementation for Visual Studio scenarios.

Changes:

  • Merges routing and refresh-server behavior into BrowserRefreshServer.
  • Adds .NET Framework HTTP/WebSocket hosting and async disposal.
  • Updates app models, dependencies, and tests for the new architecture.
File Description
test/​Microsoft.Extensions.DotNetDeltaApplier.Tests/​WebAssemblyHotReloadClientTests.cs Uses async server disposal.
test/​Microsoft.Extensions.DotNetDeltaApplier.Tests/​Mocks/​TestBrowserRefreshServer.cs Adapts the test server to the consolidated implementation.
test/​Microsoft.Extensions.DotNetDeltaApplier.Tests/​HotReloadClientsTests.cs Uses async server disposal.
test/​Microsoft.Extensions.DotNetDeltaApplier.Tests/​BrowserToolsEndpointRouterTests.cs Tests request handling through BrowserRefreshServer.
test/​Microsoft.Extensions.DotNetDeltaApplier.Tests/​BrowserRefreshServerReplayTests.cs Uses async server disposal.
test/​Microsoft.DotNet.HotReload.Client.Tests/​Microsoft.DotNet.HotReload.Client.Tests.csproj Adds VS threading support.
test/​dotnet-watch.Tests/​Web/​WebSocketConfigTests.cs Moves URL-conversion tests to WebSocketConfig.
test/​dotnet-watch.Tests/​TestUtilities/​TestBrowserRefreshServer.cs Updates the watch test server abstraction.
test/​dotnet-watch.Tests/​TestUtilities/​InProcTestWatcher.cs Disposes the watch context asynchronously.
test/​dotnet-watch.Tests/​Browser/​BrowserToolsEndpointRouterTests.cs Tests consolidated endpoint handling.
test/​dotnet-watch.Tests/​Browser/​BrowserToolsBuildOutputsTests.cs Updates session-key failure expectations.
test/​dotnet-watch.Tests/​Browser/​BrowserRefreshServerTests.cs Updates hosting and environment tests.
start-vs.cmd Supports an optional solution path.
src/​Resolvers/​Microsoft.DotNet.MSBuildSdkResolver/​Microsoft.DotNet.MSBuildSdkResolver.csproj Updates expected dependency closure.
src/​Dotnet.Watch/​Watch/​UI/​IReporter.cs Reuses shared browser-tools log events.
src/​Dotnet.Watch/​Watch/​Context/​DotNetWatchContext.cs Converts context cleanup to async disposal.
src/​Dotnet.Watch/​Watch/​Build/​ProjectGraphUtilities.cs Adds nullable Boolean property lookup.
src/​Dotnet.Watch/​Watch/​Browser/​BrowserToolsBuildOutputsExtensions.cs Maps evaluated projects to browser-tools outputs.
src/​Dotnet.Watch/​Watch/​Browser/​BrowserRefreshServerFactory.cs Starts and disposes refresh servers asynchronously.
src/​Dotnet.Watch/​Watch/​Browser/​BrowserLauncher.cs Uses the consolidated server type.
src/​Dotnet.Watch/​Watch/​AppModels/​WebServerAppModel.cs Declares gateway-proxy behavior.
src/​Dotnet.Watch/​Watch/​AppModels/​WebApplicationAppModel.cs Centralizes server creation and WebSocket configuration.
src/​Dotnet.Watch/​Watch/​AppModels/​BlazorWebAssemblyHostedAppModel.cs Declares hosted-app proxy behavior.
src/​Dotnet.Watch/​Watch/​AppModels/​BlazorWebAssemblyAppModel.cs Declares standalone gateway-proxy behavior.
src/​Dotnet.Watch/​Watch.Aspire/​Server/​AspireWatcherLauncher.cs Disposes watcher context asynchronously.
src/​Dotnet.Watch/​HotReloadClient/​WebSocketClientTransport.cs Adjusts synchronous MemoryStream access.
src/​Dotnet.Watch/​HotReloadClient/​Web/​WebSocketConfig.cs Owns HTTP-to-WebSocket URL conversion.
src/​Dotnet.Watch/​HotReloadClient/​Web/​WebServerHost.cs Adds async listener ownership and endpoint naming.
src/​Dotnet.Watch/​HotReloadClient/​Web/​WebAssemblyHotReloadClient.cs Uses the consolidated refresh server.
src/​Dotnet.Watch/​HotReloadClient/​Web/​NetFrameworkWebSocketServer.cs Adds the .NET Framework listener implementation.
src/​Dotnet.Watch/​HotReloadClient/​Web/​KestrelWebSocketServer.cs Adds async-disposal compatibility.
src/​Dotnet.Watch/​HotReloadClient/​Web/​HttpContextWrappers.cs Adapts HttpListener requests to the shared handler.
src/​Dotnet.Watch/​HotReloadClient/​Web/​BrowserToolsEndpointRouter.cs Removes the standalone router.
src/​Dotnet.Watch/​HotReloadClient/​Web/​BrowserToolsBuildOutputs.cs Makes key loading shared and failure-tolerant.
src/​Dotnet.Watch/​HotReloadClient/​Web/​BrowserRefreshServer.cs Consolidates hosting, routing, and browser communication.
src/​Dotnet.Watch/​HotReloadClient/​Web/​BrowserConnection.cs Removes the custom initialization wait helper.
src/​Dotnet.Watch/​HotReloadClient/​Web/​AbstractBrowserRefreshServer.cs Removes the former base implementation.
src/​Dotnet.Watch/​HotReloadClient/​Utilities/​TaskExtensions.cs Adds .NET Framework async polyfills.
src/​Dotnet.Watch/​HotReloadClient/​Utilities/​DisposalCancellationSource.cs Adds disposal-driven cancellation support.
src/​Dotnet.Watch/​HotReloadClient/​Microsoft.DotNet.HotReload.Client.Package.csproj Adds VS threading dependency.
src/​Dotnet.Watch/​HotReloadClient/​Logging/​LogEvents.cs Adds shared browser-tools events.
src/​Dotnet.Watch/​HotReloadClient/​HotReloadClients.cs Uses the consolidated server type.
src/​Dotnet.Watch/​HotReloadClient/​HotReloadClient.cs Renames the queued-update method.
src/​Dotnet.Watch/​HotReloadClient/​DefaultHotReloadClient.cs Updates async method naming and calls.
src/​Dotnet.Watch/​HotReloadClient/​.editorconfig Configures VS threading diagnostics.
src/​Dotnet.Watch/​dotnet-watch/​Program.cs Disposes watch context asynchronously.
eng/​Versions.props Updates async-support packages and adds VS threading.

🧠 Review effort: Balanced

@tmat
tmat force-pushed the dev/tomat/browser-refresh-cleanup branch 2 times, most recently from 76581b1 to 757532d Compare October 12, 2026 18:09
@tmat
tmat force-pushed the dev/tomat/browser-refresh-cleanup branch from 757532d to 6abc96f Compare October 12, 2026 18:38
@tmat
tmat force-pushed the dev/tomat/browser-refresh-cleanup branch from 58e09d2 to 5898c71 Compare October 12, 2026 19:03
tmat added 2 commits October 12, 2026 14:02
…tools implementation.

Browser tools is used by all Hot Reload hosts (VS, CDK) not just by dotnet-watch.
@tmat
tmat requested review from a team, akoeplinger, lewing, maraf and pavelsavara as code owners October 12, 2026 21:57
@tmat

tmat commented Oct 12, 2026

Copy link
Copy Markdown
Member Author

@rainersigwald for MSBuild version changes approval

@tmat tmat added the Area-Watch dotnet-watch label Oct 13, 2026

@DustinCampbell DustinCampbell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. I skimmed through all of the staticwebassets.json files and didn't spot anything off. (My eyes did start to swim a bit though. 😄)

Comment on lines +54 to +62
public int StatusCode
{
set => response.StatusCode = value;
}

public string? ContentType
{
set => response.ContentType = value;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there value in using setter-only properties?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These wrappers are adapting .NET Framework API to the shape used by .NET.
I only got Copilot generate those APIs that are currently used.

@tmat
tmat merged commit 680d5f1 into dotnet:main Oct 13, 2026
31 of 32 checks passed
@tmat

tmat commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

/backport to release/11.0.1xx

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0.1xx (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@tmat backporting to release/11.0.1xx failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick 680d5f1e3c8cab8342a5e939389696deea0a9286

CONFLICT (modify/delete): .github/memory/ARCHITECTURE.md deleted in HEAD and modified in 680d5f1e3c (Browser refresh server cleanup and .NET Framework impl (#56568)).  Version 680d5f1e3c (Browser refresh server cleanup and .NET Framework impl (#56568)) of .github/memory/ARCHITECTURE.md left in tree.
Auto-merging eng/Versions.props
Auto-merging src/Dotnet.Watch/AGENTS.md
Auto-merging src/Dotnet.Watch/HotReloadClient/DefaultHotReloadClient.cs
CONFLICT (content): Merge conflict in src/Dotnet.Watch/HotReloadClient/DefaultHotReloadClient.cs
Auto-merging src/Dotnet.Watch/HotReloadClient/HotReloadClient.cs
Auto-merging src/Dotnet.Watch/HotReloadClient/HotReloadClients.cs
CONFLICT (modify/delete): src/Dotnet.Watch/HotReloadClient/Web/AbstractBrowserRefreshServer.cs deleted in 680d5f1e3c (Browser refresh server cleanup and .NET Framework impl (#56568)) and modified in HEAD.  Version HEAD of src/Dotnet.Watch/HotReloadClient/Web/AbstractBrowserRefreshServer.cs left in tree.
Auto-merging src/Dotnet.Watch/HotReloadClient/Web/BrowserConnection.cs
Auto-merging src/Dotnet.Watch/HotReloadClient/Web/WebAssemblyHotReloadClient.cs
Auto-merging src/Dotnet.Watch/Watch/AppModels/BlazorWebAssemblyHostedAppModel.cs
Auto-merging src/Dotnet.Watch/Watch/AppModels/WebServerAppModel.cs
Auto-merging test/Microsoft.DotNet.HotReload.Client.Tests/Microsoft.DotNet.HotReload.Client.Tests.csproj
Auto-merging test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsBaselines/Build_DoesNotFailToCompress_TwoAssetsWith_TheSameContent.Build.staticwebassets.json
CONFLICT (content): Merge conflict in test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsBaselines/Build_DoesNotFailToCompress_TwoAssetsWith_TheSameContent.Build.staticwebassets.json
Auto-merging test/dotnet-watch.Tests/dotnet-watch.Tests.csproj
error: could not apply 680d5f1e3c... Browser refresh server cleanup and .NET Framework impl (#56568)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Move environment configuration back to AbstractBrowserRefreshServer
Using index info to reconstruct a base tree...
M	src/Dotnet.Watch/HotReloadClient/Web/AbstractBrowserRefreshServer.cs
M	src/Dotnet.Watch/Watch/AppModels/BlazorWebAssemblyHostedAppModel.cs
M	src/Dotnet.Watch/Watch/AppModels/WebServerAppModel.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Dotnet.Watch/HotReloadClient/Web/AbstractBrowserRefreshServer.cs
Auto-merging src/Dotnet.Watch/Watch/AppModels/BlazorWebAssemblyHostedAppModel.cs
Auto-merging src/Dotnet.Watch/Watch/AppModels/WebServerAppModel.cs
Applying: Move BrowserToolsBuildOutputs to client package
Applying: SessionKeyFactory
Applying: Update start-vs.cmd to accept optional solution path argument
Applying: Fold BrowserToolsEndpointRouter into BrowserRefreshServer
Applying: Add NetFrameworkBrowserRefreshServer
Using index info to reconstruct a base tree...
M	eng/Versions.props
M	src/Dotnet.Watch/HotReloadClient/DefaultHotReloadClient.cs
M	src/Dotnet.Watch/HotReloadClient/HotReloadClient.cs
M	src/Dotnet.Watch/HotReloadClient/Web/AbstractBrowserRefreshServer.cs
M	src/Dotnet.Watch/HotReloadClient/Web/BrowserConnection.cs
M	src/Dotnet.Watch/HotReloadClient/Web/WebAssemblyHotReloadClient.cs
M	test/Microsoft.DotNet.HotReload.Client.Tests/Microsoft.DotNet.HotReload.Client.Tests.csproj
Falling back to patching base and 3-way merge...
Auto-merging eng/Versions.props
Auto-merging src/Dotnet.Watch/HotReloadClient/DefaultHotReloadClient.cs
CONFLICT (content): Merge conflict in src/Dotnet.Watch/HotReloadClient/DefaultHotReloadClient.cs
Auto-merging src/Dotnet.Watch/HotReloadClient/HotReloadClient.cs
Auto-merging src/Dotnet.Watch/HotReloadClient/Web/AbstractBrowserRefreshServer.cs
Auto-merging src/Dotnet.Watch/HotReloadClient/Web/BrowserConnection.cs
Auto-merging src/Dotnet.Watch/HotReloadClient/Web/WebAssemblyHotReloadClient.cs
Auto-merging test/Microsoft.DotNet.HotReload.Client.Tests/Microsoft.DotNet.HotReload.Client.Tests.csproj
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 0006 Add NetFrameworkBrowserRefreshServer
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

@rainersigwald

Copy link
Copy Markdown
Member

@rainersigwald for MSBuild version changes approval

yeah, lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Watch dotnet-watch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants