Hot Reload in .NET 6- An Overview | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (15)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (67)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (920)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (37)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (151)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (41)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (508)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Hot Reload in .NET 6: An Overview

Hot Reload in .NET 6- An Overview

Hooray! Microsoft .NET 6 RC1 was released with so many new features and improvements. We are expecting the .NET 6 LTS (long-term support) in November 2021. For detailed information, refer to the major work planned in ASP.NET Core in .NET 6.

Hot reload is one of the most impressive features in .NET 6 and was introduced in the .NET 6 Preview 3 version. It allows us to modify the UI when the application is running by altering the code. We can see the instant reflection of those changes (after saving them) in the output without having to restart the application. With hot reload, you can quickly develop apps, save time and enhance productivity.

Hot reload works with project types such as WPF, Windows Forms, WinUI, ASP.NET Core, console applications and more.

In this blog, we are going to see how to use this .NET 6 Hot reload in a Blazor server-side application.

Prerequisites for hot reload

Following are the prerequisites for using .NET 6 hot reload:

  • .NET 6 Preview 3 or a later version.
SDKVisual Studio support
.NET 6 Preview 3Visual Studio 2019 (v16.10 latest preview)
.NET 6 Preview 4Visual Studio 2019 (v16.11 latest preview)
.NET 6 Preview 5Visual Studio 2022 (v17.0 latest preview)
.NET 6 Preview 6Visual Studio 2022 (v17.0 latest preview)
.NET 6 Preview 7Visual Studio 2022 (v17.0 latest preview)
.NET 6 RC 1Visual Studio 2022 (v17.0 latest preview)

Note: Refer to .NET 6 to see the current and upcoming .NET 6 releases and download them.

Creating a sample Blazor Server application with .NET 6

We are going to create an example Blazor Server app in .NET 6 RC 1 and Visual Studio 2022 Preview:

  1. First, open Visual Studio 2022 and select Create a new project.
    Open Visual Studio 2022 and choose Create a new project
  2. Then, type Blazor Server in the search window and select Blazor Server App from the list. Click Next.
    Type Blazor Server in search window and select the Blazor Server App
  3. Now, enter your project name and click Next.
    Enter your project name and click Next
  4. The Additional information dialog will open. Select .Net 6.0 as the target framework. The Configure for HTTPS checkbox will be selected by default when creating a new project. Then, click Create.
    Additional information dialog

Thus, we have created the Blazor Server app. Refer to the following screenshot.
Blazor Server app

How to use hot reload in a Blazor Server application

The .NET 6 hot reload works with both dotnet-watch and the Apply Code Changes button. But there are some limitations in the .NET 6 hot reload. Refer to the Supported and Unsupported code changes documentation for more details.

dotnet-watch

dotnet-watch is a development time tool that runs a .NET command when a source file changes.

Follow these steps to use hot reload using the dotnet-watch:

  1. First, open Visual Studio. Then, navigate to Tools -> Command Line -> Developer Command Prompt (or) Tools -> Command Line -> Developer PowerShell.
    Select Tools, Command Line, Developer Command Prompt or Developer PowerShell
  2. This example shows selecting the Developer PowerShell option. In the Developer PowerShell window:
    1. Navigate to the Project Directory.
    2. Then, run the dotnet watch command.
      Developer PowerShell window

    Running the dotnet-watch command will enable the hot reload and the supported edit details will be displayed in the output window.

    Then, the localhost site will be launched in the browser with the URL https://localhost:5001.
    Hot Reload sample project

  3. As I said before, with the .NET 6 hot reload, you can instantly see the changes reflected in the code. For example, you can:
  4. Also, we can execute the dotnet watch without the hot reload using the following command.
    dotnet watch --no-hot-reload

Apply Code Changes

The Apply Code Changes button will be enabled when we run the application. This button-click will update the running app with the code changes that you have made in the source even without saving the file.

Follow these steps to use .NET 6 hot reload using the Apply Code Changes button:

  1. First, run the application.
  2. Then, modify the code and click Apply Code Changes (no need to save the changes).
    Modify the code and click the Apply Code Changes button

After reloading the page, the changes will be reflected in your application.

The main limitation in the Apply Code Changes button over dotnet-watch is that the auto instant reflection does not work here. For that, we need to reload the page manually.

Note:

  • If you use hot reload with .NET 6 Preview 3 or 4, then add the “hotReloadProfile”: “aspnetcore” property to your launch profile in the launchSettings.json file.
  • For Blazor WebAssembly projects, add the “hotReloadProfile”: “blazorwasm” property in the launchSettings.json file.

Conclusion

Thanks for reading! In this article, we saw how to use the .NET 6 hot reload in a Blazor Server application. This feature can instantly update changes without the need to stop debugging or restart the app. This reduces your development time and enhances productivity.  So, try out this feature and leave your experience in the comments section below!

Syncfusion has over 1,600 components and frameworks for .NET MAUI (Preview)WinFormsWPF, WinUI, ASP.NET (Web FormsMVCCore), UWPXamarinFlutterJavaScriptAngularBlazorVue, and React. Use them to boost your application development speed.

Also, you can contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Related blogs

Tags:

Share this post:

Comments (2)

Highly informative post and explained in a precise manner that anyone can easily understand.
Thanks for sharing.
https://www.taffinc.com/dot-net-web.html

Hi TAFF,

Thanks for commenting on this post. It motivates us to create more useful blogs.

Thanks,
Mohamed Yasir K

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed