dotNET Hot Reload is Awesome
Why do I need it?
Ever done something like this?
- Build your app
- Wait for it to start
- Recognize that you need to change something
- Stop your app
- Change the code
GOTO 1
and wait again and again
With .NET 6
you can do this:
- Build your app
- Wait for it to start
- Recognize that you need to change something
- Change the code
- Immediately see the result
No more rebuilding and restarting for every little change.
That makes the developer’s inner loop faster by reducing the time between code change and seeing the result.
Note: some other languages had this feature for YEARS.
What is .NET Hot Reload?
Improve inner-loop performance for .NET developers is one of the main themes for .NET 6
.
This theme aims at two goals:
- Improving developer’s inner loop and boosting productivity
- Attracting developers from other platforms. Since most of them already have hot reloading, the absence of it in
.NET
is a blocker for switching.
.NET Hot Reload
watches your source files and applies supported code changes to your running app without restarting it. Application state also preserved.
Unsupported changes (see Limitations section) will lead to rebuild and restart.
Internaly .NET Hot Reload
uses Roslyn Edit&Continue feature.
How do I use it?
What you need
You will need .NET 6.0:
Visual Studio 2019 v.16.11 Preview 1+
or.NET 6 Preview 4+
if you plan to useVisual Studio Code
or other IDE through thedotnet watch
command
How to use with Visual Studio 2019
- Run your app
- Make supported(see Limitations section) code change
- Press the
Apply code changes
button - PROFIT! You will see changes when updated code is re-executed
How to use VS Code (or other IDE)
- Run your favorite
Terminal
app - Go to your project directory
- Run
dotnet watch
- it should indicate thatHot reload enabled
- Make supported code change and Save the file
- Wait a little :)
- ROFIT! You will see changes when updated code is re-executed
What are the Limitations?
What types of applications support .NET Hot Reload
.NET Hot Reload
will work with (it may not correctly work right now, but it will at final release on November’21):
- WPF
- Windows Forms
- .NET MAUI
- ASP.NET Core (including Blazor, Razor pages, MVC)
- Console apps
- and maybe something else
What changes are supported
Not all changes are supported.
Documentation is still in progress, but you can read Edit&Continue Roslyn docs and E&C in Visual Studio for the current list of supported edits.
When can I use it in Production?
You can start immediately - the Bing
team uses .NET 6
in Production since Preview 1
.
Or you can wait for .NET 6 Release
- November 2021.