Fix reporting Hot Reload capabilities of WASM projects#53665
Fix reporting Hot Reload capabilities of WASM projects#53665tmat wants to merge 1 commit intodotnet:release/10.0.3xxfrom
Conversation
| 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, |
There was a problem hiding this comment.
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.WithSourceto 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}."); |
There was a problem hiding this comment.
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).
| 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}."); |
| using System.Runtime.InteropServices; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.DotNet.Watch; |
There was a problem hiding this comment.
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.
| using Microsoft.DotNet.Watch; |
| 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); |
There was a problem hiding this comment.
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.
| 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); |
No description provided.