Saturday 30 January 2021

What's new in .NET 5

 .NET 5.0 is the next major release of .NET Core following 3.1. We named this new release .NET 5.0 instead of .NET Core 4.0 for two reasons:

  • We skipped version numbers 4.x to avoid confusion with .NET Framework 4.x.
  • We dropped "Core" from the name to emphasize that this is the main implementation of .NET going forward. .NET 5.0 supports more types of apps and more platforms than .NET Core or .NET Framework.

ASP.NET Core 5.0 is based on .NET 5.0 but retains the name "Core" to avoid confusing it with ASP.NET MVC 5. Likewise, Entity Framework Core 5.0 retains the name "Core" to avoid confusing it with Entity Framework 5 and 6.

.NET 5.0 includes the following improvements and new features compared to .NET Core 3.1:

.NET 5.0 doesn't replace .NET Framework

.NET 5.0 is the main implementation of .NET going forward and .NET Framework 4.x is still supported.

There are no plans to port the following technologies from .NET Framework to .NET 5.0, but there are alternatives in .NET 5.0:

.NET 5.0 DOESN'T REPLACE .NET FRAMEWORK
TechnologyRecommended alternative
Web FormsASP.NET Core Blazor or Razor Pages
Windows Workflow (WF)Open-source CoreWF or Elsa-Workflow

Windows Communication Foundation

The original implementation of Windows Communication Foundation (WCF) was only supported on Windows. However, there is a client port available from the .NET Foundation. It is entirely open source, cross platform, and supported by Microsoft. The core NuGet packages are listed below:

The community maintains the server components that complement the aforementioned client libraries. The GitHub repository can be found at CoreWCF. The server components are not officially supported by Microsoft. For an alternative to WCF, consider gRPC.

.NET 5.0 doesn't replace .NET Standard

New application development can specify the net5.0 target framework moniker (TFM) for all project types, including class libraries. Sharing code between .NET 5 workloads is simplified in that all you need is the net5.0 TFM.

For .NET 5.0 apps and libraries, the net5.0 Target Framework Moniker (TFM) combines and replaces the netcoreapp and netstandard TFMs. However, if you plan to share code between .NET Framework, .NET Core, and .NET 5 workloads, you can do so by specifying netstandard2.0 as your TFM. For more information, see .NET Standard.

C# updates

Developers writing .NET 5 apps will have access to the latest C# version and features. .NET 5 is paired with C# 9, which brings many new features to the language. Here are a few highlights:

  • Records: reference types with value-based equality semantics and non-destructive mutation supported by a new with expression.

  • Relational pattern matching: Extends pattern matching capabilities to relational operators for comparative evaluations and expressions, including logical patterns - new keywords andor, and not.

  • Top-level statements: As a means for accelerating adoption and learning of C#, the Main method can be omitted and application as simple as the following is valid:

    C#
    System.Console.Write("Hello world!");
    
  • Function pointers: Language constructs that expose the following intermediate language (IL) opcodes: ldftn and calli.

For more information on the available C# 9 features, see What's new in C# 9.

Source generators

In addition to some of the highlighted new C# features, source generators are making their way into developer projects. Source generators allow code that runs during compilation to inspect your program and produce additional files that are compiled together with the rest of your code.

For more information on source generators, see Introducing C# source generators and C# source generator samples.

F# updates

F# is the .NET functional programming language, and with .NET 5, developers have access to F# 5. Here are several new features of F# 5:

Interpolated strings

Similar to interpolated string in C#, and even JavaScript, F# supports basic string interpolation.

F#
let name = "David"
let age = 36
let message = $"{name} is {age} years old."

In addition to basic string interpolation, there is typed interpolation. With typed interpolation, a given type must match the format specifier.

F#
let name = "David"
let age = 36
let message = $"%s{name} is %d{age} years old."

This is similar to the sprintf function that formats a string based on type-safe inputs.

Visual Basic updates

There are no new language features for Visual Basic in .NET 5. However, with .NET 5, Visual Basic support is extended to:

VISUAL BASIC UPDATES
Descriptiondotnet new parameter
Console Applicationconsole
Class libraryclasslib
WPF Applicationwpf
WPF Class librarywpflib
WPF Custom Control Librarywpfcustomcontrollib
WPF User Control Librarywpfusercontrollib
Windows Forms (WinForms) Applicationwinforms
Windows Forms (WinForms) Class librarywinformslib
Unit Test Projectmstest
NUnit 3 Test Projectnunit
NUnit 3 Test Itemnunit-test
xUnit Test Projectxunit

For more information on project templates from the .NET CLI, see dotnet new.

No comments:

Post a Comment