Skip to content

Use a build-owned static asset for browser tools activation - #56386

Draft
javiercn wants to merge 5 commits into
mainfrom
javiercn-file-based-browser-activation
Draft

javiercn wants to merge 5 commits into
mainfrom
javiercn-file-based-browser-activation

Conversation

@javiercn

@javiercn javiercn commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Replace the provider-owned GET /_framework/dotnet-browser-tools/hot-reload-settings.json activation response with an application-hosted, build-only Static Web Asset at the same stable route. A normal build writes { "hotReload": false } in obj/<configuration>/<tfm>/dotnet-watch/; Watch changes that file to true after compilation before launch/relaunch, restores true after in-process rebuilds, and resets it on graceful shutdown. Writes are skipped when bytes are unchanged. No user source files are modified.

The settings asset is non-fingerprinted, excluded from compression and publish, and carries Cache-Control: no-store endpoint metadata. Its endpoint order (-1001) precedes existing host fallback endpoints. The Web and WebAssembly initializers use fetch(..., { cache: 'no-store' }) with a distinct UUID-based If-None-Match validator on each settings request. The Gateway proxy now forwards only /connect and /clear-cache; the hosting startup and provider no longer forward/serve settings. The build-owned JavaScript, RSA public/private key split, application-hosted trusted code, authenticated WebSocket/replay, and MVC/Blazor activation paths remain unchanged.

Compared with the merged endpoint approach (#56118 and #56234): provider availability no longer controls activation through a forwarded HTTP response. The build owns the disabled settings document and Watch toggles that one output file; executable browser tools and the public key still come exclusively from the application, while the provider remains limited to the authenticated socket and cache-clear routes. This PR targets main, not either prior PR branch.

Incrementality and fast up-to-date check

Normal builds update a private, non-asset completion marker after restoring the settings file to false. Design-time builds expose UpToDateCheckBuilt with that marker as the output and the settings file as Original, following the project-system fast up-to-date-check contract. A later watch write makes settings newer than the marker, so Visual Studio schedules an ordinary build rather than skipping MSBuild. That build restores false and advances the marker; repeated ordinary builds leave settings and generated metadata unchanged. The marker is removed on Clean and is neither a Static Web Asset nor published. Hosted WebAssembly reports the pair for the browser-facing client, not the server.

The SDK tests follow the repository's design-time build pattern with DesignTimeBuild=true and BuildingInsideVisualStudio=true, and emulate the project-system test cases for source-newer, source missing, and destination missing. They read the real generated UpToDateCheckBuilt/Original pair, apply the corresponding existence/timestamp decision, and call the SDK build only when needed. The Web/Gateway scenarios verify skip → build → skip, and missing settings/marker cases verify the pair stays available and the next build recreates the missing file. These tests do not run or depend on the Visual Studio CPS check itself.

Validation

  • build.cmd -nobl /v:q: passed (0 warnings, 0 errors).
  • Focused Visual Studio-style FUTDC simulation and hosted-client ownership: 5/5; prior browser-tools SWA integration: 22/22, including build → settings change → build reset, unchanged repeated build, Web/Gateway design-time item collection, hosted-client ownership, publish exclusion and Clean removal. 34 affected SWA baseline tests: 34/34; standalone and hosted WASM baseline tests: 3/3; hosting-startup tests: 5/5; watch routing and settings tests: 15/15; real Watch graceful-shutdown/settings tests: 14/14. Updated affected checked-in build baselines.
  • The reset test asserts the original disabled bytes return after a watch-style file change; LastWriteTimeUtc advances only for the changed settings file; the build manifest reflects its current timestamp at SWA's one-second precision; and a subsequent unchanged build preserves the settings bytes, timestamp, configuration timestamp, and manifest bytes. The design-time tests assert the settings Original/marker UpToDateCheckBuilt pair and that a changed settings file becomes newer than the marker before a build, but not afterward.
  • Running server-hosted Web and standalone Blazor Gateway tests: fresh If-None-Match: "browser-tools-<UUID>" requests returned HTTP 200 with false → true → true → false → false from the same host, including changes to the obj file after compilation without rebuilding/restarting the host. Build endpoints are single-route, non-fingerprinted, uncompressed, no-store metadata, and publish/clean exclude/remove the asset.
  • Actual browser evaluation of the generated Web initializer observed five 200 responses, five distinct UUID validators, false → true → true → false → false, cache: 'no-store', unchanged app PID 30428. The generated WASM initializer on the Gateway observed four 200 responses and four distinct UUID validators across false → true → true → false; its runtime activation flag followed true/false. No application restart was needed.

Cross-repository follow-up

Removing the existing Gateway and Razor Components fallback endpoints requires a separate dotnet/aspnetcore PR; none are changed here. The SWA settings endpoint takes precedence while those fallbacks remain.

Keep the settings file under intermediate output, refresh it around watch launches and rebuilds, and request it with a fresh validator to bypass stale development conditional responses. Narrow provider forwarding to connect and clear-cache, exercise live Web and Gateway hosts, and update build baselines.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 23, 2026 16:35
@azure-pipelines

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

Keep the activation contract and cross-repository ownership guidance without discussing the host behavior in code comments or PR text.

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

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.

Copilot review overview

🟡 Changes recommended

Moderate unresolved issues remain around atomic writes, launch and project cleanup, generated-asset filtering, and UUID fallback support.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

This PR moves browser-tools activation to a build-owned Static Web Asset controlled by dotnet watch, while limiting provider routing and updating Web/WASM clients, lifecycle handling, tests, and baselines.

Changes:

  • Adds build-only settings assets and endpoint metadata.
  • Updates Watch lifecycle toggling and Web/WASM cache validation.
  • Restricts provider and Gateway routes.
  • Refreshes integration tests, documentation, and generated baselines.
File Description
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Rebuild_RegeneratesJsonManifestAndCopiesItToOutputFolder.Build.staticwebassets.json Updates rebuild baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Rebuild_RegeneratesJsonManifestAndCopiesItToOutputFolder_Rebuild.Build.staticwebassets.json Updates rebuild baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Rebuild_RegeneratesJsonManifestAndCopiesItToOutputFolder_Rebuild.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​PublishWorks_With_PrecompressedAssets.Build.staticwebassets.json Updates compression baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​PublishWorks_With_PrecompressedAssets.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​PublishProjectWithReferences_WorksWithStaticWebAssetsV1ClassLibraries.Build.staticwebassets.json Updates referenced-assets baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​PublishProjectWithReferences_PublishSingleFile_GeneratesPublishJsonManifestAndCopiesPublishAssets.Build.staticwebassets.json Updates single-file publish baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​PublishProjectWithReferences_NoBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets.Build.staticwebassets.json Updates no-build baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​PublishProjectWithReferences_IncorporatesInitializersFromClassLibrariesAndPublishesAssetsToTheRightLocation.Build.staticwebassets.json Updates initializer baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​PublishProjectWithReferences_GeneratesPublishJsonManifestAndCopiesPublishAssets.Build.staticwebassets.json Updates publish baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​PublishProjectWithReferences_DifferentBuildAndPublish_LibraryInitializers.Build.staticwebassets.json Updates build/publish baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​PublishProjectWithReferences_AppendTargetFrameworkToOutputPathFalse_GeneratesPublishJsonManifestAndCopiesPublishAssets.Build.staticwebassets.json Updates output-path baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Publish_WithExternalProjectReference_UpdatesAssets.Build.staticwebassets.json Updates external-reference baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Publish_PublishSingleFile_GeneratesPublishJsonManifestAndCopiesPublishAssets.Build.staticwebassets.json Updates single-file baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Publish_NoBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets.Build.staticwebassets.json Updates no-build baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Publish_GeneratesPublishJsonManifestAndCopiesPublishAssets.Build.staticwebassets.json Updates publish baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​DoesNotFailToCompress_TwoAssetsWith_TheSameContent.Build.staticwebassets.json Updates compression baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​DoesNotFailToCompress_TwoAssetsWith_TheSameContent.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Clean_RemovesManifestFrom_BuildAndIntermediateOutput.Build.staticwebassets.json Updates clean baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​CanEnable_CompressionOnAllAssets.Build.staticwebassets.json Updates compression baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​BuildProjectWithReferences_WorksWithStaticWebAssetsV1ClassLibraries.Build.staticwebassets.json Updates referenced-assets baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​BuildProjectWithReferences_WorksWithStaticWebAssetsV1ClassLibraries.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​BuildProjectWithReferences_NoDependencies_GeneratesJsonManifestAndCopiesItToOutputFolder.Build.staticwebassets.json Updates build baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​BuildProjectWithReferences_NoDependencies_GeneratesJsonManifestAndCopiesItToOutputFolder_NoDependencies.Build.staticwebassets.json Updates no-dependencies baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​BuildProjectWithReferences_NoDependencies_GeneratesJsonManifestAndCopiesItToOutputFolder_NoDependencies.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​BuildProjectWithReferences_IncorporatesInitializersFromClassLibraries.Build.staticwebassets.json Updates initializer baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​BuildProjectWithReferences_IncorporatesInitializersFromClassLibraries.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​BuildProjectWithReferences_GeneratesJsonManifestAndCopiesItToOutputFolder.Build.staticwebassets.json Updates build baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​BuildProjectWithReferences_GeneratesJsonManifestAndCopiesItToOutputFolder.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​BuildProjectWithReferences_DeployOnBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets.Build.staticwebassets.json Updates deploy-on-build baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​BuildProjectWithReferences_CorrectlyBundlesScopedCssFiles.Build.staticwebassets.json Updates scoped-CSS baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​BuildProjectWithReferences_CorrectlyBundlesScopedCssFiles.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_WithExternalProjectReference_UpdatesAssets.Build.staticwebassets.json Updates external-reference baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_WithExternalProjectReference_UpdatesAssets.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_UpdatesManifest_WhenFilesChange.Build.staticwebassets.json Updates manifest baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_UpdatesManifest_WhenFilesChange.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_UpdatesManifest_WhenFilesChange_Updated.Build.staticwebassets.json Updates changed-manifest baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_UpdatesManifest_WhenFilesChange_Updated.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_GeneratesJsonManifestAndCopiesItToOutputFolder.Build.staticwebassets.json Updates build baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_GeneratesJsonManifestAndCopiesItToOutputFolder.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_FingerprintsContent_WhenEnabled.Build.staticwebassets.json Updates fingerprinting baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_FingerprintsContent_WhenEnabled.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_DoesNotUpdateManifest_WhenHasNotChanged.Build.staticwebassets.json Updates incremental baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_Detects_PrecompressedAssets.Build.staticwebassets.json Updates compression baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_Detects_PrecompressedAssets.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_DeployOnBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets.Build.staticwebassets.json Updates deploy-on-build baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_DefaultDocumentAndSpaFallback_CreatesAdditionalEndpoints.Build.staticwebassets.json Updates endpoint baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_CrosstargetingTests_CanIncludeBrowserAssets.Build.staticwebassets.json Updates cross-targeting baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_CrosstargetingTests_CanIncludeBrowserAssets.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_CreatesEndpointsForAssets.Build.staticwebassets.json Updates endpoint baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_Can_DisableAssetCaching.Build.staticwebassets.json Updates caching baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetsBaselines/​Build_Can_DisableAssetCaching.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​StaticWebAssetEndpointsIntegrationTest.cs Verifies settings endpoint metadata.
test/​Microsoft.NET.Sdk.StaticWebAssets.Tests/​DotNetWatchBrowserToolsIntegrationTest.cs Tests settings lifecycle and asset behavior.
test/​Microsoft.NET.Sdk.BlazorWebAssembly.Tests/​StaticWebAssetsBaselines/​StaticWebAssets_BuildMinimal_Works.Build.staticwebassets.json Updates standalone WASM baseline.
test/​Microsoft.NET.Sdk.BlazorWebAssembly.Tests/​StaticWebAssetsBaselines/​StaticWebAssets_BuildMinimal_Works.Build.files.json Updates generated files baseline.
test/​Microsoft.NET.Sdk.BlazorWebAssembly.Tests/​StaticWebAssetsBaselines/​StaticWebAssets_Build_Hosted_Works.Build.staticwebassets.json Updates hosted WASM baseline.
test/​Microsoft.NET.Sdk.BlazorWebAssembly.Tests/​StaticWebAssetsBaselines/​JSModules_ManifestIncludesModuleTargetPaths.Build.staticwebassets.json Updates JS module baseline.
test/​Microsoft.AspNetCore.Watch.BrowserRefresh.Tests/​HostingStartupTest.cs Verifies routing changes.
test/​dotnet-watch.Tests/​Browser/​BrowserToolsEndpointRouterTests.cs Tests provider routes.
test/​dotnet-watch.Tests/​Browser/​BrowserToolsBuildOutputsTests.cs Tests settings mutation.
test/​dotnet-watch.Tests/​Browser/​BrowserTests.cs Tests graceful shutdown behavior.
test/​dotnet-watch.Tests/​Browser/​BrowserRefreshServerTests.cs Tests Gateway routes.
src/​WebSdk/​Web/​Targets/​DotNetWatch/​Microsoft.NET.Sdk.BlazorWeb.DotNetWatch.lib.module.js Adds fresh settings validators.
src/​WasmSdk/​Sdk/​DotNetWatch/​Microsoft.NET.Sdk.WebAssembly.DotNetWatch.lib.module.js.template Adds fresh settings validators.
src/​StaticWebAssetsSdk/​Targets/​Microsoft.NET.Sdk.StaticWebAssets.DotNetWatch.targets Generates and registers settings assets.
src/​StaticWebAssetsSdk/​Targets/​DotNetWatch/​dotnet-watch-browser-tools.config.js.template Updates activation documentation.
src/​StaticWebAssetsSdk/​AGENTS.md Documents asset behavior.
src/​Dotnet.Watch/​Web.Middleware/​HostingStartup.cs Removes settings forwarding.
src/​Dotnet.Watch/​Web.Middleware/​ApplicationPaths.cs Removes the provider settings path.
src/​Dotnet.Watch/​Watch/​Process/​ProjectLauncher.cs Enables settings before launch.
src/​Dotnet.Watch/​Watch/​HotReload/​HotReloadDotNetWatcher.cs Manages Watch lifecycle toggling.
src/​Dotnet.Watch/​Watch/​Browser/​BrowserToolsBuildOutputs.cs Reads and writes settings state.
src/​Dotnet.Watch/​Watch/​AppModels/​WebApplicationAppModel.cs Adds settings lifecycle helpers.
src/​Dotnet.Watch/​Watch/​AppModels/​BlazorWebAssemblyAppModel.cs Restricts Gateway proxy routes.
src/​Dotnet.Watch/​HotReloadClient/​Web/​BrowserToolsProtocol.cs Removes provider settings contract.
src/​Dotnet.Watch/​HotReloadClient/​Web/​BrowserToolsEndpointRouter.cs Stops serving provider settings.
src/​Dotnet.Watch/​AGENTS.md Documents routing and lifecycle behavior.
.github/​memory/​ARCHITECTURE.md Updates architecture documentation.
.claude/​skills/​author-swa-integration-test/​references/​test-asset-catalog.md Documents the Gateway test asset.

Comment on lines +88 to +96
if (!current.AsSpan().SequenceEqual(settings))
{
try
{
File.WriteAllBytes(SettingsPath, settings);
}
catch (Exception e) when (e is IOException or UnauthorizedAccessException)
{
throw Fail($"'{SettingsFileName}' could not be updated ({e.GetType().Name})");
Comment on lines +54 to +56
if (appModel is WebApplicationAppModel webAppModel && clients.BrowserRefreshServer != null)
{
webAppModel.EnableBrowserToolsSettings(clientLogger);
@javiercn
javiercn marked this pull request as draft September 23, 2026 17:48
Write a completion marker after normal builds and expose the settings-to-marker pair to Visual Studio's design-time up-to-date check. Verify a changed settings asset is reset by the next build without rewriting unchanged assets or causing subsequent builds to rewrite settings.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@maraf
maraf self-requested a review September 23, 2026 18:36
javiercn and others added 2 commits September 24, 2026 11:39
Exercise the project-system timestamp decision with real SDK design-time items and build entry points. Cover skip, rebuild and missing-source/destination cases without adding project-system dependencies, and retain the item when either generated file is absent.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Map Razor Components in the live Web host and leave DOTNET_WATCH disabled so the existing Razor and Gateway fallback endpoints coexist with the build-owned static asset during the transition.

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

maraf commented Nov 16, 2026

Copy link
Copy Markdown
Member

@javiercn Do we still want to land this?

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants