May 25th, 2021

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

Dmitry Lyalin
Principal Program Manager

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

What is .NET Hot Reload?

With Hot Reload you can now modify your apps managed source code while the application is running, without the need to manually pause or hit a breakpoint. Simply make a supported change while your app is running and in our new Visual Studio experience use the “apply code changes” button 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 experience working with any project that is powered by .NET Framework or CoreCLR runtimes.

With Hot Reload our goal is to make this experience available no matter how you prefer to launch your app. With 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.

Getting Started

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

Visual Studio:

To try 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 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 code that can be re-executed through the running apps user interface (example: code-behind of a button or a ViewModel’s command) or something that is being triggered at an interval through a timer and change the code
  • Apply the 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.

If the change you 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’s behavior the next time the updated code is re-executed by either your action or by something like a timer triggering the code.

You can also continue to use 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 work for you, please let us know!

CLI

To try Hot Reload from the command-line when launching your app using dotnet watch:

  • Install .NET 6 Preview 4
  • Update your existing ASP.NET Core project to target .NET 6
  • Add the “hotReloadProfile”: “aspnetcore” property to your apps launch profile in launchSettings.json.

Example of Properties/launchSettings.json:

{
  "profiles": {
    "dotnet": {
      "commandName": "Project",
      "hotReloadProfile": "aspnetcore"
    }
  }
}
  • Run the project using dotnet watch and look at the output as it should indicate that hot reload is enabled
  • Make a supported code change to your apps managed source code and save the file to apply

Just like with the Visual Studio experience your new logic should now be applied and you should see the changes in your app’s behavior the next time the updated code is re-executed.

You can also use this approach with your Blazor WebAssembly projects by modifying the “blazorwasm” hot reload profile and following similar steps above. You can even try it with a Windows Forms or other types of projects powered by CoreCLR, just manually add a file named launchSettings.json under the Properties folder with the above example contents.

This experience is still in development, and we are tracking future improvement that will make it easier to use dotnet watch to Hot Reload all types of .NET Core apps without launchSettings.json files, but this is a limitation in the current release.

Best in Visual Studio 2022 & .NET 6

With today’s release this is just a preview of our full vision of Hot Reload for .NET developers. While some capability is being made available in early .NET 6 previews and in Visual Studio 2019, for the full power of this feature we are targeting .NET 6 (and future releases of .NET) and Visual Studio 2022 as the set of frameworks and tooling that will have the most complete and optimized experience.

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

  • .NET Multi-platform App UI (.NET MAUI): With .NET 6 Preview 4 developers building .NET MAUI applications can now use .NET Hot Reload with projects targeting WinUI 3. In future releases we’re bringing .NET Hot Reload support to iOS, Android, and Mac Catalyst scenarios.
  • Razor Pages: In future releases Hot Reload and Edit and Continue (EnC) will be supported for editing Razor for websites or Blazor apps targeting .NET 6 or higher
  • No Debugger Required in Visual Studio: In future release of Visual Studio 2022 we are working to add support to use Hot Reload without needing the debugger, this means developers will be able to launch their apps using CTRL-F5 and still use Hot Reload to patch their running app
  • Reducing the number of unsupported changes: In future releases of Visual Studio 2022 and .NET 6+ we’re planning 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 can be improved to better support Hot Reload. Examples of this in the future will include improvements to ASP.NET Core, .NET MAUI and other frameworks where tweaks and optimization will make Hot Reload changes more useful in more situations.

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

Supported/Unsupported changes and languages

No matter how you use .NET Hot Reload please be aware that some changes are not supported at runtime and will prompt you with a rude edit dialog and require you to restart your app in order to apply. We’re still working on the feature 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 will give you a good starting point for better understanding this new feature. For details see: EnC documentation.

Also, while the above examples are specifically mentioning C#, Visual Basic is also supported in various situations when running under Visual Studio’s debugger. F# is currently not supported in .NET 6 but we are planning to support in a future release based on customer feedback.

Your feedback matters

In this early preview release, we want to acknowledge that there will be bugs. Sometimes if you try to apply a change it might silently fail, or your app might crash, etc. If you do encounter any problems, please take a moment to report issues to us, as only with your feedback can we ensure that critical problems are resolved, and future decisions are prioritized based on your input.

To reach us please use the Visual Studio feedback mechanism.

Author

Dmitry Lyalin
Principal Program Manager

I work in the .NET team as a Program Manager with a focus on bringing Hot Reload 🔥 technology to Visual Studio and as many .NET developers as possible. I also work on .NET MAUI and XAML Tools. When not keeping busy at my virtual office I am a busy dad, who occasionally tries to find time to still be a PC Gamer.

40 comments

Discussion is closed. Login to edit/delete existing comments.

  • Keith Lewis

    Is no one going to talk about the fact that an unsupported change is called a rude edit? I mean I lost it.

  • Tanveer Badar

    Hi! Is it going to be available for azure functions?

  • Gregory · Edited

    I am fatigued hearing about hot-reload, browser-sync, dotnet watch etc etc - invariably, these never work for me.

    I am trying to move away from Visual Studio because it has become almost impossible to use because of intermittent incorrect build errors, freezing, huge build times, huge update time spans etc. I used VS code for smaller projects but have just lately started trying to use it as my main IDE because VS 2019 has become virtually...

    Read more
  • Marina Sundström

    I’m waiting for Tye to support “watch” and Hot Reload. Today it does its own thing.

  • Alex N

    Just here to express my relief/joy that F# will (eventually) get EnC support.

  • Marco · Edited

    I tested the hot reload functionality with the Weather21 app and it seems to work very well for .cs files, which really makes things a lot easier and faster.
    However, I seem to run into issues that hot reload does not seem to work for XAML files? I tried it both for WinUI and and Android, but could only get hot reload to work in .cs files and not in XAML files (e.g. changing a...

    Read more
  • Kanawanagasaki Yoko · Edited

    I cannot find list for supported project type for hot reload.
    Which projects support it?
    I tried console app and blazor webasm (without asp.net hosting) and hot reload wasn’t working. In WPF hot reload was working fine with .cs files

  • Stuart Lang

    Congrats on the Hot Reload preview! Where can we upvote F# support?

  • Jakub Jenis

    This is one of the features I’m most excited about, absolute time saver for mobile development! Will hot reload be available also for pre .net 6 stuff (.net5, .net3.1, xamarin) when using VS 2019.11, or is this tied to .net6? Thanks

    • Michel Sylvestre

      Hi! I just tried it with a core 3.1 web api in VS 2022 preview and it worked as expected!

    • Lucas Baran

      This is my exact question, would love to know .net Core 5 MVC projects work with hot reload in the new version of visual studio.

  • 21111

    Haven’t been able to use the hot reload functionality at all.
    Got VS2019 16.11 preview 1.0, and the Net6 preview 4.

    Created new Blazor Server app targetting NET6.0 preview.

    Changed the h1 element, and changed the ++1 to –1

    Nuthin.

    Verfied VS version => 16.11 preview 1
    dotnet –version => 6.0.100-preview.4.21255.9

    • Damian EdwardsMicrosoft employee

      The support for Hot Reload of changes in Razor files (.razor and .cshtml) is not available in that preview version. It will become available in a later preview. For now, it’s limited to changes in .cs files.

      • Benjamin Schmidt

        Hi,

        thats strange. Hot reload was working for me with preview 3 in Visual Studio for MAC (latest preview) with blazor server. Installing preview 4 destroed hot reload in my main app. Every edit leads to a "rude edit" error. BUT ... When i create a new blazor server app (the demo one) hot reload with razor files work. But not in my other app. If i can help let me know.

        thanks

        Read more