{"id":33015,"date":"2021-05-25T08:00:54","date_gmt":"2021-05-25T15:00:54","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=33015"},"modified":"2021-05-25T08:02:49","modified_gmt":"2021-05-25T15:02:49","slug":"introducing-net-hot-reload","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/introducing-net-hot-reload\/","title":{"rendered":"Introducing the .NET Hot Reload experience for editing code at runtime"},"content":{"rendered":"<p>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 <code>dotnet watch<\/code> command-line tooling in .NET 6 (Preview 4). In the rest of this blog post, we\u2019d 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.<\/p>\n<h2>What is .NET Hot Reload?<\/h2>\n<p>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 \u201capply code changes\u201d button to apply your edits.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/05\/dotnet-Hot-Reload-VS-2019-version-16_11.gif\"><img decoding=\"async\" class=\"alignnone wp-image-33018 size-full\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/05\/dotnet-Hot-Reload-VS-2019-version-16_11.gif\" alt=\".NET Hot Reload, apply code changes in Visual Studio 2019\" width=\"1777\" height=\"768\" \/><\/a><\/p>\n<p>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.<\/p>\n<p>With Hot Reload our goal is to make this experience available no matter how you prefer to launch your app. With today\u2019s release you can now use this experience through the fully integrated Visual Studio debugger experience or the <code>dotnet watch<\/code> command-line tool, with more options to come in later releases.<\/p>\n<h2>Getting Started<\/h2>\n<p>To get started you have the option of either using Visual Studio\u2019s newest preview release or our .NET 6 Preview 4, instructions below.<\/p>\n<p><strong>Visual Studio:<\/strong><\/p>\n<p>To try Hot Reload in Visual Studio when using the debugger:<\/p>\n<ul>\n<li>Download and install Visual Studio 2019 version 16.11 Preview 1<\/li>\n<li>Open a supported project type, for example a WPF app<\/li>\n<li>Launch the app with the debugger attached through F5 (make sure that \u201cenable native code debugging\u201d is disabled in debugger settings\/debug launch profile)<\/li>\n<li>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\u2019s command) or something that is being triggered at an interval through a timer and change the code<\/li>\n<li>Apply the code changes using the new <code>apply code changes<\/code> (ALT-F10) button in your Visual Studio toolbar (next to the <code>Continue<\/code> button). Note that saving the files is not required when using Visual Studio, giving you the flexibility to quickly change code and keep going.<\/li>\n<\/ul>\n<p>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\u2019s behavior the next time the updated code is re-executed by either your action or by something like a timer triggering the code.<\/p>\n<p>You can also continue to use other debugger features such as breakpoints, Edit &amp; 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!<\/p>\n<p><strong>CLI<\/strong><\/p>\n<p>To try Hot Reload from the command-line when launching your app using dotnet watch:<\/p>\n<ul>\n<li>Install .NET 6 Preview 4<\/li>\n<li>Update your existing ASP.NET Core project to target .NET 6<\/li>\n<li>Add the &#8220;hotReloadProfile&#8221;: &#8220;aspnetcore&#8221; property to your apps launch profile in launchSettings.json.<\/li>\n<\/ul>\n<p>Example of Properties\/launchSettings.json:<\/p>\n<pre><code class=\"language-json\">{\r\n  \"profiles\": {\r\n    \"dotnet\": {\r\n      \"commandName\": \"Project\",\r\n      \"hotReloadProfile\": \"aspnetcore\"\r\n    }\r\n  }\r\n}<\/code><\/pre>\n<ul>\n<li>Run the project using <code>dotnet watch<\/code> and look at the output as it should indicate that hot reload is enabled<\/li>\n<li>Make a supported code change to your apps managed source code and save the file to apply<\/li>\n<\/ul>\n<p>Just like with the Visual Studio experience your new logic should now be applied and you should see the changes in your app\u2019s behavior the next time the updated code is re-executed.<\/p>\n<p>You can also use this approach with your Blazor WebAssembly projects by modifying the &#8220;blazorwasm&#8221; 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.<\/p>\n<p>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.<\/p>\n<h2>Best in Visual Studio 2022 &amp; .NET 6<\/h2>\n<p>With today\u2019s 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.<\/p>\n<p>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:<\/p>\n<ul>\n<li><strong>.NET Multi-platform App UI (.NET MAUI):<\/strong> 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\u2019re bringing .NET Hot Reload support to iOS, Android, and Mac Catalyst scenarios.<\/li>\n<li><strong>Razor Pages:<\/strong> 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<\/li>\n<li><strong>No Debugger Required in Visual Studio:<\/strong> 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<\/li>\n<li><strong>Reducing the number of unsupported changes:<\/strong> In future releases of Visual Studio 2022 and .NET 6+ we\u2019re planning work across multiple teams that will reduce the number of unsupported edits at runtime<\/li>\n<li><strong>Optimizing frameworks to work best with Hot Reload:<\/strong> In .NET 6 we\u2019re 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.<\/li>\n<\/ul>\n<p>While the above are our current plans, note that plans can change based on customer feedback and schedule.<\/p>\n<h2>Supported\/Unsupported changes and languages<\/h2>\n<p>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 <code>rude edit<\/code> dialog and require you to restart your app in order to apply. We&#8217;re still working on the feature and the documentation to detail what edits are supported. For now, start by reviewing our <a href=\"https:\/\/github.com\/dotnet\/roslyn\/blob\/main\/docs\/wiki\/EnC-Supported-Edits.md\">existing list of Edit and Continue (EnC) equivalent capabilities<\/a>. Since Hot Reload is powered by EnC this will give you a good starting point for better understanding this new feature. For details see: <a href=\"https:\/\/docs.microsoft.com\/visualstudio\/debugger\/edit-and-continue?view=vs-2019\">EnC documentation<\/a>.<\/p>\n<p>Also, while the above examples are specifically mentioning C#, Visual Basic is also supported in various situations when running under Visual Studio\u2019s debugger. F# is currently not supported in .NET 6 but we are planning to support in a future release based on customer feedback.<\/p>\n<h2>Your feedback matters<\/h2>\n<p>In this early preview release, we want to acknowledge that <strong>there will be bugs<\/strong>. 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.<\/p>\n<p>To reach us please use the <a href=\"https:\/\/docs.microsoft.com\/visualstudio\/ide\/feedback-options?view=vs-2019\">Visual Studio feedback mechanism<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introducing the new .NET Hot Reload user experience for editing managed code at runtime, now available through the Visual Studio 2019 debugger and dotnet watch.<\/p>\n","protected":false},"author":692,"featured_media":33017,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685,196,195],"tags":[],"class_list":["post-33015","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-dotnet-core","category-dotnet-framework"],"acf":[],"blog_post_summary":"<p>Introducing the new .NET Hot Reload user experience for editing managed code at runtime, now available through the Visual Studio 2019 debugger and dotnet watch.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/33015","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/692"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=33015"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/33015\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/33017"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=33015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=33015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=33015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}