News

Hot Reload Leads ASP.NET Core Updates in .NET 6 Preview 5

In the brand-new .NET 6 Preview 5, the dev team has furthered Hot Reload functionality in the ASP.NET Core component, used for web development.

Microsoft this week released .NET 6 Preview 5 and Visual Studio 2022 Preview 1, with the latter mostly intended to test the groundbreaking move to a 64-bit IDE.

.NET 6 Preview 5, meanwhile, highlighted the new SDK workloads scheme that serves as the foundation for the .NET 6 unification effort, allowing for tailored workload-specific SDKs instead of the old monolithic approach, resulting in the ability to add support for new application types without increasing the size of the SDK.

On the web development front, updates to ASP.NET Core were detailed by Daniel Roth, principal program manager, ASP.NET, who led off with Hot Reload. That much-requested and long-awaited functionality -- letting developers make code changes while debugging that are instantly reflected in a running app without need of a restart -- debuted during the May Build developer conference. It was supported in an early, incomplete form in the Visual Studio 2019 version 16.11 Preview 1. Incremental Hot Reload improvements have been added since then.

Blazor Hot Reload in Animated Action
[Click on image for larger, animated GIF view.] Blazor Hot Reload in Animated Action (April) (source: Microsoft).
Blazor Hot Reload in Animated Action
[Click on image for larger, animated GIF view.] A Newer Take on Hot Reload in Animated Action (May) (source: Microsoft).

For ASP.NET Core, the main Hot Reload improvement affects dotnet watch, a command-line interface (CLI) tool that runs a .NET Core command when source files change, refreshing the browser when it detects changes to watched files. This allows live reloads of ASP.NET Core projects.

"You no longer need to specify hotReloadProfile in launchSettings.json to use .NET Hot Reload with dotnet watch", Roth said. ".NET Hot Reload with project appropriate behavior is now enabled by default. When a code edit is made that cannot be hot reloaded (a 'rude' edit), dotnet watch will now ask if you want to restart the app to apply the change."

Speaking of those "rude" edits, dotnet watch can now detect them in Blazor WebAssembly apps, the client-side component of the popular Blazor project that allows C# to be the main programming language for web apps instead of JavaScript. Applied changes to such apps will be reapplied with a browser refresh or when the app is loaded in a separate browser tab or browser instance.

In response to question from a developer, Roth explained that .NET Hot Reload works with .razor files when using dotnet watch, though that capability is coming in a future Visual Studio update.

Also on the Blazor WebAssembly front, download sizes have been reduced via a feature known as relinking. In that client-side hosting model -- as opposed to Blazor Server -- a Blazor app and its dependencies are downloaded to the browser in parallel, along with the WebAssembly-based .NET runtime. That can be time-consuming depending on connection speeds and other factors.

Relinking allows unneeded runtime logic -- such as globalization -- to be stripped out of the runtime download.

"In .NET 6 Preview 5, you can now use the .NET WebAssembly tools (the same tools used for .NET WebAssembly AOT compilation) to relink the runtime to remove unneeded logic and dramatically reduce the size of the runtime," Roth explained. "If you have the .NET WebAssembly workload installed, runtime relinking is done automatically when you publish the app. The size reduction is particularly dramatic when using invariant globalization mode." The graphic below illustrates the effect, specifically the transfer size of dotnet.wasm for a default Blazor WebAssembly project with .NET 5 and .NET 6:

Download Size Comparison
[Click on image for larger view.] Download Size Comparison (source: Microsoft).

In response to another reader comment, Roth noted that there are known issues with using ASP.NET Core in .NET 6 Preview 5. GitHub release notes list the following:

  • Running Blazor WebAssembly using IIS Express in Development

    As of .NET 6 Preview 1, there is an ongoing issue with running Blazor WebAssembly applications using an IIS Express server during development on Visual Studio. As a workaround, we recommend using Kestrel during development.

  • Incremental builds in VS not working for apps with Razor views

    As of .NET 6 Preview 3, changes to Razor views will not be updated during incremental builds. As a workaround, you can:

    • Build from the command line
    • Configure VS to always call MSBuild when building projects
    • Clean and build projects to pick up changes

Roth listed other ASP.NET Core highlights of .NET 6 Preview 5 as:

  • ASP.NET Core SPA templates updated to Angular 11 and React 17
  • Use Razor syntax in SVG foreignObject elements
  • Specify null for Action and RenderFragment component parameters
  • Configurable buffer threshold before writing to disk in Json.NET output formatter
  • Subcategories for better filtering of Kestrel logs
  • Faster get and set for HTTP headers
  • Configurable unconsumed incoming buffer size for IIS

"We hope you enjoy this preview release of ASP.NET Core in .NET 6. We're eager to hear about your experiences with this release. Let us know what you think by filing issues on GitHub," Roth concluded.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube