.NET 6 Features and Updates

Needless to say, the anticipation of .NET 6 was overwhelming. We have covered several articles building up to .NET 6 and its features. Now that .NET 6 has been released, we can take a look at all of its features properly.

What are the New Features of .NET 6?

Below, we will discuss some of the newest and most important features of .NET 6 for developers. They include single-file binary deployment, API logging updates, and version checking, to name but a few.

Single-file Apps

With .NET 6, you can now publish a single-file binary that is both deployed and launched as a single file, not only for Windows and macOS as with .NET 5, but for all supported operating systems. These apps, known as single file apps, do not need to extract core runtime assemblies to temporary directories in order to work. They make use of a building block named superhost, which is similar to apphost, but instead of launching ordinary applications due to its code that finds, loads, and starts as with apphost, it does these tasks, as well as, using a statically linked copy of all the CoreCLR native binaries.

It is also important to note that, at the time of this writing, single-file apps can only be debugged using platform debuggers, such as WinDBG. Microsoft says they are looking at adding Visual Studio debugging with a later build of Visual Studio 2022.

Read: .NET 5 Versus .NET 6 Preview

LoggerMessageAttribute Type

The new LoggerMessageAttribute type, included in the Microsoft.Extensions.Logging namespace, is new and source-generates performant logging APIs. Source-generation logging delivers performant logging solutions for modern .NET applications.

Source-generation is triggered only if the LoggerMessageAttribute is used on partial logging methods. It can auto generate implementations of partial methods as well as produce compile-time diagnostics with hints about proper usage.

Benefits of decorating methods with the LoggerMessageAttribute are as follows:

Make use of a declarative attribute instead of coding boilerplate.
The generator gives warnings aiding developers to do the right thing.
Support for dynamic log level.

Here is a small example of using the LoggerMessageAttribute in .Net:

public static partial class Log
{
    [LoggerMessage(EventId = 0, Level = LogLevel.Critical, Message = "Database offline `{DatabaseName}`")]
    public static partial void DatabaseConnError(ILogger logger, string DatabaseName);
}

SDK Version Checking

.NET 6 includes the dotnet sdk check command, which tracks when new SDK and Runtime versions are available, as shown in the following image:

Features of .Net 6

Minimal Windows Applications

.NET 6 includes minimal templates for Windows Forms. The following is a minimal Windows Forms application with .NET 6:

class Program
{
    [STAThread]
    static void Main()
    {
        ApplicationConfiguration.Initialize();
        Application.Run(new Form1());
    }
}

ApplicationConfiguration.Initialize() here, is source generated and emits the following calls:

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.SetDefaultFont(new Font(...));
Application.SetHighDpiMode(HighDpiMode.SystemAware);

New Microsoft UI Automation Providers

UIA providers are software objects that expose elements so that accessibility client applications can retrieve the elements’ information and invoke their functionality. In .NET 6 UIA providers for CheckedListBox, LinkLabel, Panel, ScrollBar, TabControl and TrackBar have been added.

Hannes DuPreez
Hannes DuPreez
Ockert J. du Preez is a passionate coder and always willing to learn. He has written hundreds of developer articles over the years detailing his programming quests and adventures. He has written the following books: Visual Studio 2019 In-Depth (BpB Publications) JavaScript for Gurus (BpB Publications) He was the Technical Editor for Professional C++, 5th Edition (Wiley) He was a Microsoft Most Valuable Professional for .NET (2008–2017).

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read