Hot Reload is coming to .NET development
Posted: (EET/GMT+2)
Microsoft has introduced the .NET Hot Reload experience, which allows some code changes to be applied while the application is still running.
The idea is simple: make a change, apply it, and continue testing without always rebuilding and restarting the whole application.
For command-line development, the interesting entry point is dotnet watch.
dotnet watch run
Start an ASP.NET Core application with that command, edit a supported C# or Razor file, and the tooling attempts to apply the change to the running process.
This is especially useful for small UI and API changes where restarting the application would otherwise interrupt the flow.
For example, update an endpoint:
app.MapGet("/", () => "Hello from Hot Reload");
Save the file and check whether the running application reflects the change. Note that Hot Reload does not mean every possible code change can be applied at runtime. Some changes still require a rebuild or restart. There are also between 32 and 64 bit applications.
Good cases for Hot Reload include:
- small method body changes
- Razor page updates
- simple endpoint changes
- CSS and markup adjustments (great!).
Less suitable cases include:
- large refactoring work
- project file changes
- package reference changes
- startup and hosting changes.
In summary, treat Hot Reload as a development convenience, not as a replacement for normal builds and tests.
For ASP.NET Core developers, this is a welcome productivity feature. The best part is not that it changes how applications are built, but that it shortens the edit-test loop during normal development.