Skip to content

Instantly share code, notes, and snippets.

@Chiamaka-Uzuegbu
Created September 21, 2023 21:04
Show Gist options
  • Save Chiamaka-Uzuegbu/ca3426decc30f33ca653a45df30f349a to your computer and use it in GitHub Desktop.
Save Chiamaka-Uzuegbu/ca3426decc30f33ca653a45df30f349a to your computer and use it in GitHub Desktop.

What is Hot Reload?

Hot Reload in .NET works by applying code changes, which includes changes to stylesheets, and mostly to a running app without having to restart the app and without losing app state. Hot Reload is supported for ASP.NET Core version 6.0 and later versions used for building projects. This feature is great for fixing bugs quickly even while running the application. Some people call it, "Edit and Continue".

What is the Significance of Hot Reload

In the earlier versions of .NET and .NET Core, this feature was not present. What that meant was that, you have to stop running your application if and when you discover some bugs, or you need to make a change to your code, while debugging. The constant stopping and starting of the application can be ifact herculean and uninteresting. Hence, the introduction of the Hot reload within the Visual Studio IDE.

However, Hot Reloads may not work for every pause and fix while debugging your code. If you missed including a significant part of the code before debugging, you may need to stop running your application to include that before running. This is because the last instance of your build before effecting a change, would still be present. You cannot include a service or middleware you forgot to put while coding, when debugging by using Hot Reload. The running system is likely not going to pick that change. It's okay to see the Hot Reload feature as an emergency edit and continue tool, and not used for inputting code blocks that should have been present earlier.

Frame Works that Support it

Hot Reload works with many of familiar and upcoming project types such as WPF, Windows Forms, .NET MAUI previews, ASP.NET Core apps code-behind, Console applications, WinUI 3 (managed debugger required) and much more. This support is quite detailed with the core experience of working with any project that is powered by .NET Framework or CoreCLR runtimes.

The goal of introducing the Hot Reload is to make this experience available no matter the preference of launching the app. The current release makes it possible to experience the feature through the fully integrated Visual Studio debugger or the dotnet watch command-line tool, with more options to come in later releases.

Getting Started with Hot Reload in Visual Studio

To get started the option of either using Visual Studio’s newest preview release or our .NET 6 Preview 4 is available. See instructions below.

To use Hot Reload in Visual Studio with the debugger, do the following:

  • Download and install Visual Studio 2019 or 2022.
  • Open a supported project type, for example an ASP.Net Core Web API, or a class library.
  • Launch the app with the debugger attached through F5 (make sure that “enable native code debugging” is disabled in debugger settings/debug launch profile)
  • Open a C# code file with some pre-written code that can be re-executed through the running apps user interface.
  • Apply your code changes using the new apply code changes (ALT-F10) button in your Visual Studio toolbar (next to the Continue button).

Note that saving the files is not required when using Visual Studio, giving you the flexibility to quickly change code and keep going.

To read further about Hot Reload click here: Hot Reload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment