Speed up your .NET and C++ development with Hot Reload in Visual Studio 2022

Dmitry Lyalin

With the recent release of Visual Studio 2022 Preview 2 we’d like to use this blog post to dive deeper into the brand-new Hot Reload experience which works for both managed .NET and newly supported native C++ apps.

With Hot Reload our goal is to save you as many app restarts between edits as possible, making you more productive by reducing the time you spend building/restarting as you continue to build your app. We try to achieve this goal by making it possible for you to edit your applications code files and, in many cases, apply those code changes immediately without having to do things such as pause the apps execution or restarting.

This brand-new Hot Reload technology for code files also continues to work side-by-side with XAML Hot Reload, making both XAML and .NET Hot Reload available for those applications that use XAML for UI. Hot Reload also works alongside existing debugger capabilities you might be used to such as breakpoints, ‘edit and continue’ (EnC) for modify running code at a breakpoint and other features.

In this release Hot Reload works with many types of apps, this includes those powered by XAML such as WPF and WinUI 3, and many others such as Windows Forms, ASP.NET web apps, Blazor Server, Console apps and almost anywhere else where a modern .NET runtime is used in combination with the Visual Studio debugger.

Image Dev17 WinUI HotReloadGif

In addition, we are actively working to support more app types in the near future, such as Blazor Wasm and .NET MAUI iOS/Android. Watch for us announcing support for additional type of apps in future releases.

While the Hot Reload experience has now been available for public preview since Visual Studio 2019 version 16.11, in this post we will go into the specific details of what’s new in Visual Studio 2022 Preview 2 and provide a glimpse into what’s coming (or at least planned to be delivered) in future preview releases.

What’s new in Visual Studio 2022 Preview 2

In this release we’re excited to announce major improvements to our Hot Reload experience, highlights include things such as our initial support for editing Razor pages in your ASP.NET web applications, support for Hot Reloading C++ apps during the debugger experience, the ability to use .NET Hot Reload without the debugger when launching the app with CTRL-F5 and support for more types of edits.

Alongside these improvements this release also has various bug fixes and stability enhancement. Below let’s dive into the details of each area.

Hot Reload for ASP.NET (Blazor Server & Razor Pages)

In this release .NET Hot Reload support extends beyond editing ASP.NET code-behind which was previously available. With this release it now possible to edit Blazor Server apps for editing .Razor files and being able to apply supported changes without rebuilding/restarting.

ASP.NET scenarios also now support refreshing the browser automatically after a Hot Reload change is applied. This is currently only supported when using CTRL-F5 to launch your app and is coming to the debugger (F5) in future previews.

Finally, ASP.NET developers now have the ability to apply their changes via Hot Reload when saving and not only when pressing the apply code changes button. This feature is on by default in this preview and will be configurable and more broadly available to other type of apps in future releases.

Support for C++ apps while using the debugger

Starting with this preview, we are now making it possible to use the Hot Reload experience in Visual Studio to also apply code changes to running C++ applications while using the Visual Studio debugger (F5).

To use this feature, open your existing C++ project, start the app with the debugger attached, make changes to your code, and use the “Apply Code Changes” button while the app is running. Re-executing the code again through interacting with any UI interface in your application or timer will trigger the new changes without having to restart the app or having to wait for a breakpoint to be hit.

Image Dev17 CPlusPlus HotReloadGif

Below are some additional details C++ developers should be aware of:

  • C++ Hot Reload is powered by native Edit and Continue, for supported edits and limitations see our documentation.
  • You can edit any codebase compiled by MSVC toolset, as long as you use the /ZI compiler switch.
  • You can edit both exe and DLL projects.
  • Hot Reload injects your changes into the app dynamically and won’t trigger a full rebuild of the app.
  • Hot Reload functions the same as Edit & Continue but does not require break mode debugging. You no longer need to set a break point.
  • If you need the program stopped before making changes, please use Edit and Continue. Otherwise, Hot Reload will provide the best experience.
  • C++ Hot Reload only works when using the Visual Studio debugger, and while .NET Hot Reload is coming to CTRL-F5 and CLI experiences, this is not currently planned for C++ apps at this time.
  • C++ Hot Reload is supported for both CMake and MSBuild C++ projects (note: this blog was updated on January 18th 2022 to indicate CMake is now supported)

This is just the start of our journey to explore what is possible for C++ developers. We hope you test this feature and give us feedback on what is working well and what is not working with both Hot Reload as well as Edit and Continue scenarios in C++.

Please participate in a 3-minute Hot Reload for C++ Survey

Support for .NET Hot Reload when running without the debugger (CTRL-F5)

In the initial release of .NET Hot Reload earlier this year we first enabled the experience when running your .NET app under the debugger (F5). In this release we are now also starting to support launching your .NET 6 app without the debugger through the CTRL-F5 mechanism while still retaining support to apply changes as the app runs.

Our goal with this feature is to make Hot Reload available in more scenarios, so no matter how you like to run your .NET app during development (such as F5, CTRL-F5 or CLI) we are making Hot Reload available in all of them.

In this release this feature is available for Windows Forms, WPF, Console, ASP.NET Core and Blazor Server apps. At the moment, other app types will not work or might not be stable. We’ll continue to make more improvements to this experience in future releases, so stay tuned!

Do note that using the debug build configuration and .NET 6 are both requirements for using Visual Studio’s new Hot Reload experience when launching your app through CTRL-F5 or CLI. Debugger (F5) also requires the debug configuration, but in terms of supported .NET versions it is more broadly available anywhere Edit and Continue is supported.

More Supported edits & multi-process stability improvements for .NET apps

In this release we are adding support for additional types of edits for .NET developers, these improvements apply to both Hot Reload and edit and continue experiences.

These improvements include:

  • Limited support for editing Razor files (.Razor files only at this time).
  • Adding, updating or deleting Custom Attributes.
  • Adding or updating Record structs.
  • Editing Switch expressions.
  • Editing files with #line directives, including changes to the directive itself.

In addition, we’ve also invested into improving the stability of both Hot Reload and Edit and Continue in scenarios where you use the multi-start feature of a solution to start more than one process at the same time. This feature didn’t work reliably so we addressed the problems, and it should now be fully functional.

What’s Next?

With Visual Studio 2022 Preview 2 we’re excited to have delivered some key planned features, and with Preview 3 and beyond we will deliver additional functionality. Below is a preview of what we hope to deliver, of course plans are always subject to change but here is our current roadmap:

  • Support for Blazor web apps in more scenarios, such as support for Blazor Wasm and hybrid .NET MAUI desktop apps.
  • Support for editing CSS files during Hot Reload, enabling you to both change code-behind and the CSS files of your app during the same session with CSS changes reflecting in real-time.
  • Supporting .NET MAUI iOS and Android scenario for Hot Reloading mobile apps through the debugger (F5). Please note that supporting non-debugger scenarios such as CTRL-F5 and CLI are currently below the cutline for what we can deliver in .NET 6 timeframe.
  • Additional improvements to the user experience in Visual Studio 2022, this includes an improved rude edit dialog, a new settings panel, an option to enable hot reload to apply changes “on file save” and more.

Ready to try Hot Reload?

If you’re now excited to try Hot Reload with your projects, here is how you can get started:

  • Install Visual Studio 2022 Preview 2 and open your existing .NET or C++ project and start the application in the debug configuration.
  • Once the app is running switch back to Visual Studio, make a supported edit and use the new “apply code changes (ALT-F10)” button in the debug toolbar to apply your changes to the running application.

Hot Reload button in Visual Studio 2022

  • Now re-execute the code which was updated to see the new logic. You can do so either through an action in your apps UI or through something like a timer that can re-trigger the logic. If the code changed is never re-executed then Hot Reload will not apply the changes (for example if your code is running, Hot Reload cannot update it until it stops executing and restarts again).

If the change you made cannot be applied, you’ll see something we call a ‘rude edit’ dialog that lets you know an app restart is required to apply those changes. In this case you can either try a different type of edit or restart the app to continue development.

Your Feedback Matters

Your feedback really helps us build better products and Hot Reload is no exception, we really appreciate you taking the time to try our newest feature and we hope you will report problems using the Visual Studio feedback mechanism. Things we’d love to hear about include:

  • If you find that Hot Reload causes something to crash or behave unexpectedly (your app or Visual Studio itself).
  • If Hot Reload fails to work correctly in a way that is confusing.
  • If Hot Reload doesn’t deliver the productivity improvements you were hoping for, we’d like to understand the details.

And anything else you want to share.

Thank you!