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

2

5

If I create a new Blazor WASM app, out of the box I can use Hot Reload by running dotnet watch run in a terminal window. This will launch a browser window, and any changes I make will update in the browser automatically.

However, if I start my app in Visual Studio with the debugger attached (F5), I don't get any hot reload functionality. When I make a change, Visual Studio shows a message in the bottom left that says Code Changes were applied successfully, but the browser does not refresh. If I refresh the browser manually, I still do not see my changes.

I have "Hot Reload on Save" checked. Pressing the new Hot Reload button doesn't seem to do anything.

The browser refresh script is injected into my html. <script src="/_framework/aspnetcore-browser-refresh.js"></script>

I am using Visual Studio 2022 Version 17.0.0 Preview 7.0, and dotnet 6 RC 2 (6.0.0-rc.2.21480.10).

Is it not possible to use Hot Reload while debugging a Blazor WASM app, or am I missing something?

Dipterocarpaceous answered 3/11, 2021 at 14:12 Comment(0)
A
10

Update

This bug has been fixed as of version 17.1 of Visual Studio 2022.


Posterity

This feature is currently unsupported when using the debugger in WebAssembly apps. 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, this will be fixed in the 17.1 release of VS 2022.

The fix will be included in the 17.1 release.

The latest preview version of Visual Studio 2022 (17.1.0 Preview 2 released Jan 5, 2022) contains the fix for this. I tested this personally and verified it's working. Note that you will still need to wait for 17.1 if you don't want to use the preview channel.

Arst answered 3/11, 2021 at 14:24 Comment(5)
I'm of the opinion that this answer should be a comment...Process
@Process how do you figure? I'm honestly mystified by that suggestion. If this question is valid, then this is the answer to the question.Arst
Your answer is merely stating that that feature is not yet supported, providing a link to the docs. Again, in my opinion it should be a comment, not an answer. I don't think you violate the rules of stackoverflow, yet I find it problematic ...Process
I'm also confused by the "should be a comment" suggestion. The question was "is this possible?" and this is a perfectly good answer.Compellation
I found a workaround by using CTRL+F5 and attaching the debugger to the process after the host finishes loading. It works as it should, but can be a bit tedious to repeat. Using visual studio 2022 professional. Could be automated somehow?Resect
T
0

Now fixed, just update Visual Studio 2022 to the latest version (v17.1)!

When Microsoft first launched VS 2022 they clarified that Hot Reload was not fully supported for WASM and that they would hopefully be supporting it in a future patch of 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.

They have included the fix for this in VS 2022 version 17.1 which was officially released on February 15, 2022.

I updated and can confirm that hot reload while debugging is working for me!

Tarrah answered 16/2, 2022 at 19:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.