Search code examples
blazorblazor-webassemblyhot-reloadasp.net-blazor

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


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?


Solution

  • 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.