调试 Blazor WASM(Aspnet 托管)时无法使用热重载

Unable to use Hot Reload while debugging Blazor WASM (Aspnet hosted)

如果我创建一个新的 Blazor WASM 应用程序,开箱即用,我可以在终端 window 中通过 运行 dotnet watch run 使用热重载。这将启动浏览器 window,我所做的任何更改都会自动更新到浏览器中。

但是,如果我在 Visual Studio 中启动我的应用程序并附加了调试器 (F5),我将无法获得任何热重载功能。当我进行更改时,Visual Studio 会在左下角显示一条消息 Code Changes were applied successfully,但浏览器不会刷新。如果我手动刷新浏览器,我仍然看不到我的更改。

我选中了“保存时热重载”。按新的 Hot Reload 按钮似乎没有任何作用。

浏览器刷新脚本 注入到我的 html 中。 <script src="/_framework/aspnetcore-browser-refresh.js"></script>

我正在使用 Visual Studio 2022 版本 17.0.0 预览版 7.0 和 dotnet 6 RC 2 (6.0.0-rc.2.21480.10)。

在调试 Blazor WASM 应用程序时无法使用热重载,还是我遗漏了什么?

更新

从 Visual Studio 2022 的 17.1 版开始,此错误已得到修复。


后代

在 WebAssembly 应用程序中使用调试器时,目前不支持此功能。 According to Microsoft:

*In Visual Studio 2022 GA release Hot Reload support for Blazor WebAssembly when using the Visual Studio debugger isn’t enabled yet. You can still get Hot Reload If you start your app through Visual Studio without the debugger, and we are working to resolve this in the next Visual Studio update.

According to Microsoft,这将在 VS 2022 的 17.1 版本中修复。

The fix will be included in the 17.1 release.

Visual Studio 2022 的最新 preview 版本(17.1.0 Preview 2 于 2022 年 1 月 5 日发布)包含针对此问题的修复。我亲自对此进行了测试并验证了它的工作原理。请注意,如果您不想使用预览通道,您仍然需要等待17.1。

现已修复,只需更新 Visual Studio 2022 至最新版本 (v17.1)!

当 Microsoft 首次发布 VS 2022 时,他们澄清说 WASM 不完全支持热重载,他们希望在 VS 2022 的未来补丁中支持它。

https://devblogs.microsoft.com/dotnet/update-on-net-hot-reload-progress-and-visual-studio-2022-highlights/

Blazor Wasm being the one exception that only works today when launching your app without the debugger, but we will fix this in a future update as previously mentioned.

他们已在 2022 年 2 月 15 日正式发布的 VS 2022 版本 17.1 中包含对此的修复。

我更新了并且可以确认调试时热重载对我有用!