dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.33k stars 9.97k forks source link

Hot Reload nearly always fails, with Blazor WebAssembly and "dotnet watch" #45519

Closed szalapski closed 1 year ago

szalapski commented 1 year ago

Is there an existing issue for this?

Describe the bug

Please get Hot Reload to work reliably and consistently with Blazor WebAssembly, especially with changes to .razor files. This feature seems so buggy when it should "just work". It seems to work much better with non-Blazor server-side changes, e.g. to a Web API, but that's not where much productivity benefit would result.

When using dotnet watch on my Server project, with verbose logging , I get watch : Hot reload capabilities: . (not even Baseline) and, on a change, No hot reload changes to apply. (when there are). This is with .NET 7.0.0 and SDK 7.0.100 on a solution that was created with .NET 6 and recently upgraded to 7.

Starting...
dotnet watch πŸ”₯ Hot reload capabilities: .
dotnet watch ⌚ File changed: .\MySoln\Client\Shared\MainLayout.razor.
dotnet watch ⌚ No deltas modified. Applying changes to clear diagnostics.
dotnet watch ⌚ Received 1 from browser in [Count: 1, MessageType: Binary, EndOfMessage: True].
dotnet watch ⌚ No hot reload changes to apply.
dotnet watch πŸ”₯ Hot reload change handled in 4092.6926ms.

When running from VS (with or without debugging), I get similar output: image, or sometimes instead "Your debugged process might be corrupted and restarting it is recommended nearly always."

The most relevant issue seems to be https://github.com/dotnet/aspnetcore/issues/40587, but there must be much more to that one that isn't working right.

See also:

Seems like there are a lot of others struggling too but not commenting in GitHub issues, e.g.

.NET Version

7.0.0

Anything else?

dotnet --info

.NET SDK: Version: 7.0.100 Commit: e12b7af219

Runtime Environment: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.100\

Host: Version: 7.0.0 Architecture: x64 Commit: d099f075e4

.NET SDKs installed: 5.0.408 [C:\Program Files\dotnet\sdk] 6.0.403 [C:\Program Files\dotnet\sdk] 7.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

wf-soft commented 1 year ago

I use a Bootstrap Blazor framework, and my CSS cannot be hot overloaded, it seems to be easily disturbed,

After installing. net 8, my blazer project must add

<UseRazorSourceGenerator>false</UseRazorSourceGenerator>

to start, and any hot overloads will fail

jadenrogers commented 1 year ago

When will 7.0.3xx SDK be released?

szalapski commented 1 year ago

it was not fixed. I wish someone would have tested it with the provided example before deeming it "likely fixed". The test is very easy.

Here's the minimal example, the same one that was provided in https://github.com/dotnet/aspnetcore/issues/45519, now upgraded to use SDK 7.0.302

szalapski/HotReloadIssue45519Demo

Clone this and run

dotnet watch --verbose --project ./TradeCars/Server

The site should start up. You'll see Hot reload capabilities: . which portends the failure. Edit anything in Index.razor to watch hot reload fail.

As requested, I have piggybacked on the same issue in 7.0.302 at #47836

tmat commented 3 weeks ago

@szalapski We have made major changes (partial rewrite) of dotnet-watch in .NET 9 focused on systematically addressing reliability issues. Using the latest bits the repro above (after updating the projects to net9.0) seems to be working well. We have also significantly improved logging in --verbose mode. Would you mind giving the latest preview a try? If anything doesn't work please open a new issue with the output of dotnet watch --verbose. Thanks for patience and apologies it took a while.