Today, we are pleased to introduce you to the availability of the.NET hot reload experience in Visual Studio 2019 16.11 (Preview 1) and the DotNet Watch command line tool (Preview 4) in.NET 6. In this post, we want to take the opportunity to explain to you what.NET hot reloading is, how to get started with it, what our vision is for future planned improvements, and clarify the types of editing and languages currently supported.

What is.NET hot reloading?

With hot overloading, you can now modify application-managed source code while the application is running without manually pausing or clicking breakpoints. Just make the supported changes while the application is running, and in our new Visual Studio experience, apply your edits using the Apply Code Changes button.

Hot reloading applies to many of your existing and upcoming project types, such as WPF, Windows Forms,.NET Maui Previews, ASP.NET Core application backend code, console applications, WinUI 3 (with a managed debugger required), and more. This support is extensive, with core experience working with any project supported by the.NET Framework or the CoreCLR runtime.

With hot overloading, our goal is to provide this experience no matter how you prefer to launch your application. In today’s release, you can now use this experience through the fully integrated Visual Studio Debugger experience or the DotNet Watch command line tool, and more options will be available in future releases.

An introduction to

First, you can choose to use the latest Preview version of Visual Studio or our.NET 6 Preview 4, as described below.

Visual Studio:

To try hot reloading in Visual Studio while using the debugger:

  • Download and install Visual Studio 2019 16.11 Preview 1
  • Open supported project types, such as WPF applications
  • Start the application with the F5 connection to the debugger (make sure to disable “Enable native code debugging” in the debugger Settings/debug startup configuration file)
  • Open a C# code file that contains code that can be re-executed and changed by the running application user interface (for example: backend code for a button or commands from a ViewModel) or code that is triggered by a timer at regular intervals
  • Use the New Application Code Changes (Alt-F10) button in the Visual Studio toolbar (next to the Continue button) to apply the code changes. Note that you don’t need to save files when using Visual Studio, which gives you the flexibility to quickly change your code and move on.

If the changes you made are supported, your application will now be patched when it runs with the new logic, and you should see the changes in the application’s behavior the next time you re-execute the updated code through your actions or a timer like the one that triggers the code.

You can also continue to use other debugger features, such as breakpoints, edit and continue, XAML hot reload, and so on. All the features you use today should work in full parallel with.NET hot reloads. If anything doesn’t suit you, please let us know!

Command line interface

To try hot reloading from the command line when launching an application using Dotnet Watch:

  • Install.NET 6 Preview 4
  • Update the existing ASP.NET core project as the target. NET 6
  • Add the “hotreloadProfile” : “aspNetCore” property to the launchSettings.json application launch profile.

The Properties/launchSettings json example:

{
  "profiles": {
    "dotnet": {
      "commandName": "Project",
      "hotReloadProfile": "aspnetcore"
    }
  }
}
  • Use DotNet Watch to run the project and look at the output, as it should indicate that hot overloading is enabled
  • Make supported code changes to your application-managed source code and save the files for application Just as in the Visual Studio experience, you should apply the new logic now, and the next time you re-execute the updated code, you should see a change in application behavior.

You can also use this method for your Blazor WebAssembly project by modifying the “BlazorWASM” hot-reload configuration file and following similar steps above. You can even try it out using Windows Forms or one of the other types of projects supported by CoreCLR by manually adding a file under the Properties folder called launchSettings.json that contains the above sample content.

This experience is still in development, and we are tracking future improvements that will make it easier to hot-reload all types of.NET Core applications without the LaunchSettings.json file using DotNet Watch, but this is a limitation in the current version.

Best in Visual Studio 2022 and.NET 6

In today’s release, this is just a preview of our full vision of hot reloading for.NET developers. While some functionality was available in the early.NET 6 Preview and Visual Studio 2019, in order to make the most of this functionality, we are using.NET 6 (and future.NET releases) and Visual Studio 2022 as a set of frameworks and tools. For the most complete and optimized experience.

To give you an idea of what types of functionality we plan to offer in future previews and final releases, here are some examples:

  • .NET Multiplatform Application UI (.NET Maui) : With.NET 6 Preview 4, developers building.NET Maui applications can now use.NET Hot Reload for WinUI 3 oriented projects. In future releases, we will provide.NET Hot Reload support for iOS, Android, and Mac Catalyst.
  • Razor page: In future releases, hot reload and edit and continue (ENC) will be supported to edit Razor for.NET 6 or later Web sites or Blazor applications
  • The debugger is not required in Visual Studio: In future releases of Visual Studio 2022, we are working on adding support for using Hot reloading without a debugger, which means developers will be able to launch their applications using Ctrl-F5 and still be able to patch their running applications using Hot Reload
  • Reducing the number of unsupported changes: In future releases of Visual Studio 2022 and.NET 6+, we plan to work across multiple teams to reduce the number of unsupported edits at runtime
  • Optimizing the framework to work best with hot overloading: In.NET 6, we are looking at how to improve some of the frameworks to better support hot overloading. Future examples will include improvements to ASP.NET Core,.NET Maui, and other frameworks, where tweaks and optimizations will make hot-reloading changes more useful in more cases. Although the above is our current plan, please note that the plan is subject to change based on customer feedback and schedule.

Supported/unsupported changes and languages

Regardless of how you use.NET hot reloading, be aware that some changes are not supported at runtime and will prompt you with a Rude edit dialog that requires you to restart the application before you can apply it. We are still working on the feature and documentation to specify which edits are supported. For now, let’s review our existing list of “edit and continue” (ENC) equivalents. Since hot overloading is supported by ENC, this will give you a good starting point to better understand this new feature. For more information, see: ENC documentation.

In addition, while the above example specifically mentions C#, Visual Basic also supports a variety of situations when running under Visual Studio’s debugger. .NET 6 does not currently support F#, but we plan to do so in a future release based on customer feedback.

Your feedback is important

In this early preview, we acknowledge that there will be bugs. Sometimes, if you try to apply a change, it might silently fail, or your application might crash, and so on. If you do experience any problems, please take the time to report them to us, because it is only through your feedback that we can ensure that key issues are addressed and resolved, and future decisions will be prioritized based on your input.

To contact us, please use the Visual Studio feedback mechanism or ask any development questions on the Microsoft Q&A forum.