This article is more than 1 year old

Microsoft previews Hot Reload for .NET developers, sets date for .NET 6

Faster Entity Framework, complete C++ 20 support in Visual Studio, but complications remain

Build Microsoft has previewed Hot Reload for .NET development, enabling on-the-fly changes to source code that are applied to a running application. The company also set the date for the first production release of .NET 6: November 9.

Long-time Microsoft-platform developers will recall Edit and continue (EnC) as a feature of Visual Basic way back when that was lost in the transition to .NET, and then regained in Visual Studio 2005.

Hot Reload is not the same feature, though according to senior program manger Dmitry Lyalin, "Hot Reload is powered by EnC."

Edit and continue requires pausing the code at a breakpoint, making the edit, and resuming, whereas Hot Reload does not require a pause.

We tried the feature in Visual Studio 2019 16.11 preview, using .NET 6.0 preview, and the feature worked well in a simple example. It also works the next time the code that is changed is re-executed; it does not reload the application. This is handy when fixing a bug or experimenting with code that runs on a button click, for example, saving time. XAML Hot Reload is an existing feature that is specifically for updating XAML-based user interfaces on the fly.

Clicking the Apply code changes button will update a running application without a pause, all going well

Click to enlarge

VS Code users can also try Hot Reload, using a utility called dotnet watch. This utility has existed for several years and runs a .NET core command when source files change.

It can be used to refresh the browser when a page changes, to recompile code, or to run tests. The dotnet watch utility can now be configured to support Hot Reload, by modifying a launch settings file.

Still coming

Lyalin said that more features are planned for the release of .NET 6 and Visual Studio 2022. Future plans include .NET Hot Reload for iOS, Android and Mac Catalyst applications, Razor and Blazor applications, applications running in release mode (currently debug mode is needed), and fewer limitations over what can be changed. Currently C# has the best support, Visual Basic has some support, and F# is not yet supported.

At the virtual Build event under way this week, Microsoft also unveiled .NET 6 preview 4, and gave the date of November 9 for general availability. .NET 6 is a big release since it is the first long-term support version of the unified .NET that succeeds both .NET Framework and .NET Core (though it is really .NET Core). Program manager Richard Lander said that production use of .NET 6 will be possible from August, using what the company calls go-live builds. .NET 6 will be supported for three years and the official list of platforms has been extended to include Android, iOS, Mac and Mac Catalyst for x64 and Apple Silicon, and Windows Arm64.

Lander mentioned new features in preview 4, including rewritten FileStream that performs faster and uses much less memory (Lander gave an example which shows memory allocations dropping from 39kB to 1kB).

He also said that the code for EventPipe, a mechanism for "egressing events, performance data and counters," has been migrated from C++ to C, the reason being to support the Mono runtime with the same code.

ASP.NET Core in the.NET 6 preview 4 has a new feature, called minimal APIs. "These streamlined APIs provide the benefits of ASP.NET MVC with less ceremony", said principal program manager Daniel Roth.

A skeleton API app can now be written in a few lines of code in one file, he said.

The team is also taking advantages of new features in C# 10 to enable more concise code. "The developer goes from using classes and methods to using lambdas without giving up the ability to use attributes and other features," said Roth.

There is also new logging middleware, optimisation for Entity Framework Core, and simplified templates for single-page applications.

There is an important change for Blazor WebAssembly applications, which now support compilation directly to WebAssembly rather than running on a .NET runtime implemented in WebAssembly.

The performance improvement "can be quite dramatic," said Roth, giving an example that was 5 times faster. It is also now possible to host Blazor components in a .NET MAUI (Multi-Platform App UI, the successor to Xamarin Forms) application, as a route to building cross-platform native applications using a web user interface.

The difference between this and alternatives like Electron is that developers can write everything in C#, though the extent to which that is desirable is up for debate. The evidence is that some .NET developers are quite taken with Blazor.

Blazor WebAssembly apps will now be compiled direct to Wasm rather than running as .NET intermediate language on a Wasm .NET runtime.

Blazor WebAssembly apps will now be compiled direct to Wasm rather than running as .NET intermediate language on a Wasm .NET runtime

Microsoft has also updated Visual Studio 2019 (no sign of Visual Studio 2022 yet, though a preview was promised in the summer). Visual Studio 2019 16.10 (the production version) now has a feature-complete C++ 20 computer and STL, according to senior program manager Justin Johnson.

There are also improvements to the Git support, an improved .NET performance profiler using a new analysis engine, and some other tweaks.

Finally, the Entity Framework Core team has reported performance improvements in the forthcoming version for .NET 6. EF Core as executing queries 31 per cent faster, and in combination with other .NET 6.0 improvements, 70 per cent faster than version 5.0.

The team said it was inspired by Dapper, an alternative to EF Core that is much faster, maintained and used by StackOverflow, and that it has narrowed the performance gap to 5 per cent on some benchmarks.

Although Microsoft is putting huge effort into making sense of its sprawling .NET platform, there are still areas of confusion.

A developer asked whether Xamarin would now use the same base class libraries as .NET on Windows. "Yes", said Lander, but "The answer is a tiny bit more nuanced."

He observed that rather than .NET on Windows, it was more precisely .NET 6 cross-platform libraries on Windows, and that "there may always be a different behavior for certain APIs in iOS vs Windows vs Linux, depending on what the OS enables."

Write once, test everywhere.®

More about

TIP US OFF

Send us news


Other stories you might like