Skip to content

Fix reporting Hot Reload capabilities of WASM projects#53665

Open
tmat wants to merge 1 commit intodotnet:release/10.0.3xxfrom
tmat:FixWasmCapabilityLogging
Open

Fix reporting Hot Reload capabilities of WASM projects#53665
tmat wants to merge 1 commit intodotnet:release/10.0.3xxfrom
tmat:FixWasmCapabilityLogging

Conversation

@tmat
Copy link
Copy Markdown
Member

@tmat tmat commented Apr 1, 2026

No description provided.

if (projectHotReloadCapabilities.IsEmpty)
{
logger.LogDebug("Project specifies capabilities: {Capabilities}.", capabilitiesStr);
// Note that this is not possible with SDK 10+ since the WASM SDK always defines the capabilities in the project,
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.

The condition was inverted.

@tmat tmat marked this pull request as ready for review April 1, 2026 23:52
@tmat tmat requested a review from a team as a code owner April 1, 2026 23:52
Copilot AI review requested due to automatic review settings April 1, 2026 23:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates dotnet watch / Hot Reload logging and associated tests to correctly report WebAssembly (Blazor WASM) Hot Reload capabilities, including distinguishing between capabilities coming from the project vs. inferred defaults.

Changes:

  • Add a dedicated log event/message for “Project specifies capabilities” and update WASM hot reload client logging accordingly.
  • Update tests to cover capability reporting across target frameworks/package versions and align with updated browser-refresh logging messages.
  • Extend TestAsset.WithSource to support overriding target framework and package version property substitutions for test scenarios.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/TestAssets/TestProjects/WatchBlazorWasm/blazorwasm.csproj Removes an older SelfContained workaround from the WASM test asset.
test/Microsoft.NET.TestFramework/TestAsset.cs Enhances WithSource to allow overriding TFM and package version substitutions.
test/dotnet-watch.Tests/HotReload/RazorHotReloadTests.cs Updates WASM Hot Reload tests to validate capability reporting and updated messages.
test/dotnet-watch.Tests/Browser/BrowserTests.cs Updates expectations for the renamed browser-refresh middleware message descriptor.
src/Dotnet.Watch/Watch/UI/IReporter.cs Adds new message descriptor and renames browser-refresh message descriptor.
src/Dotnet.Watch/Watch/AppModels/WebApplicationAppModel.cs Updates logging to use the renamed browser-refresh middleware descriptor.
src/Dotnet.Watch/HotReloadClient/Web/WebAssemblyHotReloadClient.cs Adjusts WASM capability logging and introduces a new log event usage.
src/Dotnet.Watch/HotReloadClient/Logging/LoggingUtilities.cs Fixes a typo in the tuple element name returned from ParseCategoryName.
src/Dotnet.Watch/HotReloadClient/Logging/LogEvents.cs Adds new log events for WASM capability-source reporting.

public static readonly LogEvent<None> ConnectedToRefreshServer = Create(LogLevel.Debug, "Connected to refresh server.");
public static readonly LogEvent<string> ManifestFileNotFound = Create<string>(LogLevel.Debug, "Manifest file '{0}' not found.");
public static readonly LogEvent<string> ProjectSpecifiesCapabilities = Create<string>(LogLevel.Debug, "Project specifies capabilities: {0}.");
public static readonly LogEvent<(Version, string)> UsingCapabilitiesBasedOnTargetFrmameworkVersion = Create<(Version, string)>(LogLevel.Debug, "Using capabilities based on project target framework version: '{0}': {1}.");
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

LogEvents introduces UsingCapabilitiesBasedOnTargetFrmameworkVersion (note the typo in “Frmamework”). This makes the API harder to discover and easy to miss when searching; please rename it to UsingCapabilitiesBasedOnTargetFrameworkVersion (and update call sites).

Suggested change
public static readonly LogEvent<(Version, string)> UsingCapabilitiesBasedOnTargetFrmameworkVersion = Create<(Version, string)>(LogLevel.Debug, "Using capabilities based on project target framework version: '{0}': {1}.");
public static readonly LogEvent<(Version, string)> UsingCapabilitiesBasedOnTargetFrameworkVersion = Create<(Version, string)>(LogLevel.Debug, "Using capabilities based on project target framework version: '{0}': {1}.");

Copilot uses AI. Check for mistakes.
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.DotNet.Watch;
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

using Microsoft.DotNet.Watch; appears unused in this file. Since this repo treats warnings as errors, this will fail the build (CS8019); please remove it or use a type from that namespace if it’s intended.

Suggested change
using Microsoft.DotNet.Watch;

Copilot uses AI. Check for mistakes.
public static readonly MessageDescriptor<(int, string)> UpdateBatchFailedWithError = Create(LogEvents.UpdateBatchFailedWithError, Emoji.HotReload);
public static readonly MessageDescriptor<(int, string)> UpdateBatchExceptionStackTrace = Create(LogEvents.UpdateBatchExceptionStackTrace, Emoji.HotReload);
public static readonly MessageDescriptor<string> Capabilities = Create(LogEvents.Capabilities, Emoji.HotReload);
public static readonly MessageDescriptor<string> ProjectSpecifiesCapabilities = Create(LogEvents.ProjectSpecifiesCapabilities, Emoji.HotReload);
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

WebAssemblyHotReloadClient now logs LogEvents.UsingCapabilitiesBasedOnTargetFrmameworkVersion when projectHotReloadCapabilities is empty. LoggerFactory.Logger unconditionally calls MessageDescriptor.GetDescriptor(eventId) for non-zero event ids, so this new event will throw if it’s ever emitted (no MessageDescriptor is registered for it). Either add a MessageDescriptor for UsingCapabilitiesBasedOnTargetFrmameworkVersion here alongside the other LogEvents.* descriptors, or log this message without a non-zero EventId (e.g., LogDebug) to avoid the lookup.

Suggested change
public static readonly MessageDescriptor<string> ProjectSpecifiesCapabilities = Create(LogEvents.ProjectSpecifiesCapabilities, Emoji.HotReload);
public static readonly MessageDescriptor<string> ProjectSpecifiesCapabilities = Create(LogEvents.ProjectSpecifiesCapabilities, Emoji.HotReload);
public static readonly MessageDescriptor<string> UsingCapabilitiesBasedOnTargetFrmameworkVersion = Create(LogEvents.UsingCapabilitiesBasedOnTargetFrmameworkVersion, Emoji.HotReload);

Copilot uses AI. Check for mistakes.
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.

2 participants