Introducing the .NET Hot Reload feel for editing code at runtime

Dmitry

Today, we are excited to introduce you lot to the availability of the .NET Hot Reload experience in Visual Studio 2019 version 16.11 (Preview one) and through the dotnet watch command-line tooling in .NET 6 (Preview iv). In the rest of this blog post, we'd like this opportunity to walk you through what is .NET Hot Reload, how you tin get started using this feature, what our vision is for future planned improvements and clarity on what blazon of edits and languages are currently supported.

What is .NET Hot Reload?

With Hot Reload you tin now modify your apps managed source code while the application is running, without the demand to manually intermission or hit a breakpoint. Simply brand a supported modify while your app is running and in our new Visual Studio experience use the "utilize code changes" push to apply your edits.

.NET Hot Reload, apply code changes in Visual Studio 2019

Hot Reload works with many of your existing 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 many others. This support is very broad with the core feel working with whatever project that is powered by .NET Framework or CoreCLR runtimes.

With Hot Reload our goal is to make this experience available no affair how you adopt to launch your app. With today's release yous can at present use this feel through the fully integrated Visual Studio debugger feel or the dotnet sentry command-line tool, with more options to come in after releases.

Getting Started

To go started you take the option of either using Visual Studio's newest preview release or our .NET 6 Preview four, instructions beneath.

Visual Studio:

To endeavor Hot Reload in Visual Studio when using the debugger:

  • Download and install Visual Studio 2019 version 16.11 Preview 1
  • Open a supported project type, for example a WPF app
  • Launch the app with the debugger fastened through F5 (brand sure that "enable native code debugging" is disabled in debugger settings/debug launch profile)
  • Open a C# lawmaking file with some code that can be re-executed through the running apps user interface (example: code-backside of a button or a ViewModel's command) or something that is beingness triggered at an interval through a timer and change the code
  • Apply the lawmaking changes using the new utilize code changes (ALT-F10) button in your Visual Studio toolbar (next to the Keep button). Note that saving the files is not required when using Visual Studio, giving you the flexibility to quickly change lawmaking and keep going.

If the alter yous made is supported your app will now be patched while its running with your new logic and you should see the changes in your app'south behavior the next time the updated code is re-executed by either your activeness or past something like a timer triggering the code.

Y'all can also continue to utilise other debugger features such as breakpoints, Edit & Continue, XAML Hot Reload, etc. Everything that you are used to today should fully work in parallel with .NET Hot Reload. If something does not piece of work for you, please let us know!

CLI

To endeavor Hot Reload from the control-line when launching your app using dotnet watch:

  • Install .NET half-dozen Preview iv
  • Update your existing ASP.NET Core project to target .NET six
  • Add the "hotReloadProfile": "aspnetcore" holding to your apps launch profile in launchSettings.json.

Example of Properties/launchSettings.json:

          {   "profiles": {     "dotnet": {       "commandName": "Project",       "hotReloadProfile": "aspnetcore"     }   } }        
  • Run the project using dotnet picket and look at the output every bit information technology should signal that hot reload is enabled
  • Brand a supported code change to your apps managed source lawmaking and salvage the file to employ

Just like with the Visual Studio experience your new logic should now be applied and you should come across the changes in your app's behavior the next fourth dimension the updated lawmaking is re-executed.

You tin can likewise use this approach with your Blazor WebAssembly projects by modifying the "blazorwasm" hot reload contour and post-obit similar steps above. Yous can even try it with a Windows Forms or other types of projects powered by CoreCLR, simply manually add a file named launchSettings.json under the Backdrop folder with the above example contents.

This experience is nevertheless in development, and nosotros are tracking hereafter improvement that will make it easier to utilise dotnet watch to Hot Reload all types of .Internet Core apps without launchSettings.json files, simply this is a limitation in the current release.

Best in Visual Studio 2022 & .NET 6

With today's release this is merely a preview of our total vision of Hot Reload for .NET developers. While some adequacy is existence fabricated available in early .NET 6 previews and in Visual Studio 2019, for the total power of this feature nosotros are targeting .NET 6 (and future releases of .Net) and Visual Studio 2022 as the prepare of frameworks and tooling that will have the nigh complete and optimized experience.

To give y'all a glance into what type of features we program to deliver in future previews and our final release here are some examples:

  • .Internet Multi-platform App UI (.NET MAUI): With .Net vi Preview 4 developers building .NET MAUI applications can at present employ .Internet Hot Reload with projects targeting WinUI 3. In future releases we're bringing .Cyberspace Hot Reload support to iOS, Android, and Mac Catalyst scenarios.
  • Razor Pages: In hereafter releases Hot Reload and Edit and Continue (EnC) will exist supported for editing Razor for websites or Blazor apps targeting .Internet half dozen or college
  • No Debugger Required in Visual Studio: In hereafter release of Visual Studio 2022 nosotros are working to add back up to use Hot Reload without needing the debugger, this means developers will be able to launch their apps using CTRL-F5 and even so use Hot Reload to patch their running app
  • Reducing the number of unsupported changes: In time to come releases of Visual Studio 2022 and .NET 6+ we're planning piece of work across multiple teams that will reduce the number of unsupported edits at runtime
  • Optimizing frameworks to work best with Hot Reload: In .NET 6 we're investigating how certain frameworks tin be improved to ameliorate back up Hot Reload. Examples of this in the time to come will include improvements to ASP.Net Core, .Net MAUI and other frameworks where tweaks and optimization will brand Hot Reload changes more useful in more situations.

While the above are our current plans, note that plans tin can alter based on customer feedback and schedule.

Supported/Unsupported changes and languages

No matter how y'all apply .NET Hot Reload please exist enlightened that some changes are not supported at runtime and volition prompt you with a rude edit dialog and require yous to restart your app in order to apply. Nosotros're nonetheless working on the characteristic and the documentation to detail what edits are supported. For now, start by reviewing our existing list of Edit and Continue (EnC) equivalent capabilities. Since Hot Reload is powered by EnC this volition give y'all a good starting point for better agreement this new characteristic. For details meet: EnC documentation.

Besides, while the to a higher place examples are specifically mentioning C#, Visual Bones is also supported in various situations when running under Visual Studio's debugger. F# is currently not supported in .Internet 6 but we are planning to support in a futurity release based on client feedback.

Your feedback matters

In this early preview release, nosotros want to admit that in that location will be bugs. Sometimes if you try to apply a change information technology might silently fail, or your app might crash, etc. If you do encounter any issues, please take a moment to study problems to usa, as only with your feedback can we ensure that disquisitional issues are resolved, and future decisions are prioritized based on your input.

To attain united states please use the Visual Studio feedback mechanism.