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!

15 comments

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

  • Paulo Pinto 0

    What about hot-reload after changing IDL files in XAML C++, is that even on the roadmap?

    • Dmitry LyalinMicrosoft employee 0

      Hi Paulo,

      This is not currently on our roadmap as far as I know. If you can please file a VS Feedback ticket with all the details of what you are looking for we will review it, thank you!

      • Paulo Pinto 0

        Hi Dimitry thanks for replying, however if it isn’t on the roadmap I won’t bother to submit any ticket.

        My experience with C++/WinRT related tickets for C++ tooling improvement beyond a Visual C++ 6.0/ATL, is that they are ignored anyway.

  • Reilly Wood 0

    I’ve been using Hot Reload preview functionality for a few months now in various forms and it’s so, so good. It’s a complete game-changer for the inner-loop developer experience in .NET, kudos to everyone who worked on it.

    I’d love to read a deep dive on the technology behind Hot Reload sometime. It seems quite closely linked to Edit+Continue, but clearly something has changed to let E+C be used in a new way.

    • Dmitry LyalinMicrosoft employee 0

      Hi Reilly,

      Thank you for taking the time to send us this feedback, it is really great to hear it is working great for you. If you do find problems or if certain limitations are causing you to lose a lot of productivity, please send us a VS feedback ticket with details or you can even contact me through Twitter directly. Hot Reload is powered by EnC at its core and we’re expanding its capability a lot from that starting point, so we’re excited to unblock many scenarios for .NET developers to benefit from.

  • MgSam 0

    I hope you guys have really improved this substantially from the current state of Edit and Continue. I won’t know until VS 2022 releases as I don’t have the bandwidth to test preview versions. I’ve found in VS 2019 and earlier EnC works maybe 5% of the time for me. Heck, sometimes even just stepping through code makes VS think that a verboten change happened and forces a restart of debugging.

    I really hope to hear some news soon on the update of C# Interactive to .NET Core and maybe making it usable from the debugger. To me, that would provide a huge step up in usability.

    • Dmitry LyalinMicrosoft employee 0

      MgSam,

      It is very true that EnC has various limitations and depending on how your app is coded many of them could be blockers forcing restarts to still be required. There are less of these with Hot Reload (and EnC is benefiting too!) but not every unsupported scenario is resolved in the .NET 6 timeframe. I do hope you give Hot Reload a true and we’ll continue to make it better over time, we really believe we can get there, and this first release will lay the foundation for the future.

      For the C# Interactive that is interesting feedback, can you file a VS feedback ticket that describes exactly what you would hope we implement there and tell them to flag me on the ticket?

  • Ondřej Koller 0

    Hi Dmitry,
    do you possibly consider supporting Avalonia apps as well ? http://avaloniaui.net/

    Ondrej

  • Siddharth Abbineni 0

    Hi,

    Is there currently a way to debug a Blazor WASM + API (net core hosted) solution with hot reload?

    • Dmitry LyalinMicrosoft employee 0

      Blazor Wasm Hot Reload support is still in development, stay tuned for more updates on this in the next few releases.

  • bogdan radacina 0

    Thanks a lot guys. I’ve been using it for 2 months with an older preview of .NET 6 on an ASP.NET core app from VSCode with dotnet cli. Works pretty nicely. The only downside is when I edit the .razor files (mostly javascript snippets), the watch process crashes and I need to rebuild but it’s not a huge deal. I’ll install the latest preview sdk and see how things have improved.
    Thanks again!

    • Dmitry LyalinMicrosoft employee 0

      Bogdan,

      Really happy you are helping give this a test run! We actually don’t know this bug, could you please help us report the details by filing a GitHub issue here? https://github.com/dotnet/aspnetcore. It would be a huge help

  • Florian 0

    One complaint I’d have – which is more about edit and continue though – is that when you edit code with the app paused and create a compiler error you can not always see which one it is. If you’re lucky, the error will show in the error window, but it doesn’t always appear there or maybe only with a huge delay. So when it’s not in the error list, I would typically check the tooltip of the underlined code, but error tooltips don’t appear when the app is paused. This is a major struggle 🙁

    Since I don’t always want to continue running my app while changing code (for example when I’m stepping through code and see an issue I’d want to change the code immediately) I don’t see hot reload as a solution for that.

  • Guy 0

    For ASP.NET I find that `dotnet watch run` is a bit more performant upon recompile. The `dotnet watch` feels a bit different and maybe a better experience.

    For example, saving a file will interrupt and recompile with `dotnet watch` but not in Visual Studio. If I edit a file and save then immediately make another change before compilation is done then save visual studio will not interrupt the build to capture the most recent save. This is not the same experience.

    For now, I’m sticking with `dotnet watch` and if I need to debug, I just attach the debugger to the app.

  • Marshal Hayes 0

    Thank you for writing this great article! I’m particularly excited about the next steps for supporting live CSS file edits.

    In an application I’m working on which uses Tailwind‘s just-in-time mode, oftentimes modifying the Razor view alone doesn’t do enough. This is because the stylesheets for said views are generated (not static) and 100% depend on how they’ve been used.

    Currently, I’m able to work around this by using UpToDateCheckBuilt to execute a yarn script which compiles the stylesheets given a glob to the Razor views. This requires a full application rebuild, which of course defeats the purpose of hot reloading.

    Are there any plans for supporting ways to explicitly run pre- or post-scripts when certain files are modified?

Feedback usabilla icon