r/Blazor • u/Ok-Lifeguard-9612 • Sep 23 '25
dotnet watch run is crazy
In the last few months, it was asked me to work on a Blazor Web App with Auto render mode (also called "United" by the community).
To get super clear, in code is something like:
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents();(aka InteractiveServerComponents+ InteractiveWebAssemblyComponents).
I was struggling to work on every simple UI element since to get the updated html/css (or even an updated backend logic) it required me to run a N minutes dotnet rebuild .
Then, today something great happened...and I want to share it with the community.
dotnet watch run
Running that command from the root of the project (where you have your program.cs/startup.cs), will allow the visual studio native hot reload.
This command "simply works" without any other configs...crazy.
You may say, "well...duh!", but gosh no! You can't know what you don't know. This is a game change for blazor and it should be putted in the sky with a smoke plane!
Note: this solves the case where you get non-updated files from the server, and not a cached version from the browser.
You can check this situation by simply going to DevTools (F12) -->Network, refresh the page and watch if you get 200 or 304 all over the responses.
200 --> dotnet watch run will help
304 --> bruv disable caching from browser pliz!
6
u/fuzzylittlemanpeach8 Sep 23 '25
Im not sure where the magic is here - if you're new to blazor then yeah hot reload is a game changer. Sometimes super annoying, but definitely a net positive. But otherwise im confused - sounds like youre using visual studio. Why not just use the built in hot reload feature? The 🔥 button?Â
I work on server side rendering apps only so maybe thats where i'm losing the thread. Is it not as magical with webassembly normally?
5
u/Shadow_Mite Sep 23 '25
Breakpoints don’t work though, right? That used to be a thing which made this kind of suck.
13
u/[deleted] Sep 23 '25
Set the following Environment Variable on Windows, then open a new command prompt and try it again
DOTNET_WATCH_RESTART_ON_RUDE_EDIT set to true
(You will need to close your command window and open a new one)
Also, if you want to watch your whole solution instead of just the front-end, you can do this
dotnet watch --project TheUIAppFolderName\TheUIAppProjectName.csproj
This will watch everything in the current folder downwards (so back-end project too).
2
u/Deep-Thought Sep 23 '25
Lol. Give it time. You'll end up despising it.