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

What is.NET hot reloading?

With hot overloading, you can now modify application-hosted source code while the application is running without having to manually pause or click a breakpoint. Simply make the supported changes while the application is running, and use the “Apply Code Changes” button to apply your edits in our new Visual Studio experience.

Hot reloads apply to many of your existing and upcoming project types, such as WPF, Windows Forms,.NET MAUI Preview, ASP.NET Core application background code, console applications, WinUI 3 (which requires a managed debugger), and more. This support is very broad, with core experience working with any project supported by the.NET Framework or the CoreCLR runtime.

With hot reloading, 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, with more options to come in later 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 overloading in Visual Studio when using the debugger:

• Download and install Visual Studio 2019 version 16.11 Preview 1

• Open supported project types, such as WPF applications

• Start the application with the F5 connection debugger (make sure “Enable native code debugging” is disabled in the debugger Settings/Debug launch configuration file)

• open a C# code file that contains code that can be re-executed and changed through the running application user interface (for example: the code behind a button or a ViewModel command) or through code that is triggered by a timer at regular intervals

• Apply code changes using the New Application Code Changes (Alt-F10) button in the Visual Studio toolbar (next to the Continue button). Note that there is no need to save files when using Visual Studio, which gives you the flexibility to quickly change the code and move on.

If the changes you made are supported, your application will now be patched when run with the new logic, and you should see changes in the application’s behavior the next time the updated code is re-executed through your action or a similar timer that triggers the code.

You can also continue to use other debugger features such as breakpoints, edit and Continue, XAML hot overloading, and so on. Everything you use today should work in full parallel with.NET hot overloads. 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 with Dotnet Watch:

  • Install.NET 6 Preview 4
  • Update existing ASP.NET core projects to 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"}}}Copy the code
  • Run the project with dotnet Watch and view the output, as it should indicate that hot overloading is enabled
  • Make supported code changes to the source code managed by your application and save the file to apply

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 the application’s behavior.

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

This experience is still a work in progress, and we’re tracking future improvements that will make it easier to hot-reload all types of.NET Core applications using DotNet Watch without a launchSettings.json file, but this is a limitation in the current release.

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 features are available in early.NET 6 previews and Visual Studio 2019, to get the most out of this feature, we’re using.NET 6 (and future.NET releases) and Visual Studio 2022 as a set of frameworks and tools, To get the most complete and optimized experience.

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

  • .NET Multi-platform 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 offer.NET Hot Reload support for iOS, Android, and Mac Catalyst.
  • Razor Pages: In future releases, hot reload and Edit and Continue (EnC) will be supported to edit Razor for.NET 6 or later websites or Blazor applications
  • No debugger required in Visual Studio: In a future version of Visual Studio 2022, we’re working to add support for using Hot overloads without the need for 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
  • Reduce 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 run time
  • Optimize frameworks to best work with hot overloading: In.NET 6, we are looking at ways to improve some 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 overload changes more useful in more cases.

While the above are our current plans, please note that plans are subject to change based on customer feedback and schedules.

Supported/unsupported changes and languages

Regardless of how you use.NET hot overloads, please note that some changes are not supported at run time and will prompt you with an rude edit dialog and require you to restart the application before they can be applied. We are still working on the functionality and documentation to specify which edits are supported. Now, let’s first 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 capability. For more information, see: EnC documentation.

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

Your feedback is important

In this early preview, we acknowledge that there will be errors. 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 the problem to us, because only through your feedback can we ensure that the key issues are addressed, 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.