.NET Core 3 Introduce new features

.NET Core 3 Introduce new features

.Net Core is a free and open-source cross-platform software framework for Windows, Linux and macOS. .NET Core 3.0 was announced on May 7, 2019 and was officially released on September 23, 2019 and the later version .NET Core 3.1 was released just a few months later, on December 3, 2019. The .Net Core team has made many improvements and new features in this version. Let’s find out what these new features are in this article. However, in the scope of this article, we only introduce some outstanding features such as programming with Windows Forms, WPF in .NET Core, Blazor framework, new features of C # 8. If you want to learn fully about .NET Core 3.0 and .NET Core 3.1, refer to the link provided at the end of the article.

Supported platforms

All the supported operating systems are listed below (based on what was announced officially from Microsoft):

  • Alpine: 3.9+
  • Debian: 9+
  • openSUSE: 42.3+
  • Fedora: 26+
  • Ubuntu: 16.04+
  • RHEL: 6+
  • SLES: 12+
  • macOS: 10.13+
  • Windows Client: 7, 8.1, 10 (1607+)
  • Windows Server: 2012 R2 SP1+

Download

You can get started using .Net Core by downloading it. Or if you already experienced with .NET Core before, you can install new version by using the following link.

https://dotnet.microsoft.com/download/dotnet-core

Integrated Development Environment

With new C# 8.0 included, it’s highly recommended that you use Visual Studio 2019 version 16.3  or newer, Visual Studio for Mac 8.3 or newer, or Visual Studio Code to create your applications in .Net Core 3.0.

Porting from .NET framework and .NET Core 2

If you came from .NET framework, the following article may be helpful for you to port from .NET framework to .net core generally by providing the overview of the porting process and a list of useful tools.

https://docs.microsoft.com/en-us/dotnet/core/porting/

If you want to migrate from .NET Core 2 to .NET Core 3, some of the obsolete features that may affect your applications are listed below.

https://docs.microsoft.com/en-us/dotnet/core/compatibility/2.2-3.0

What’s new in .NET Core 3?

Windows forms and Windows Presentation Foundation (WPF):

.NET Core 3 brings support for Windows Desktop apps built with WPF and Windows Forms. But for now, this feature is only supported on Windows. Although the .NET Core Runtime is cross-platform, but with the desktop frameworks, your desktop applications still reply on underlying Windows platform.

You can migrate your Windows Forms and WPF applications using .NET Core. Or you can create new applications with just a few simple commands (.NET Core CLI). After migrating, your applications can get so many benefits from .Net Core 3 such as framework deployments (self-contained or side-by-side), better runtime performance for certain classes of APIS (such as I/O and networking), new language features in C# 8, and Windows 10 capabilities (MSIX packaging technology, platform APIS via NuGET, and UI updates with XAML Islands.)

dotnet new wpf
dotnet new winforms

Visual Studio 2019 adds New Project templates for .NET Core 3 Windows Forms and WPF.

Blazor:

Blazor is a framework in ASP.NET Core for building interactive client-side web UI. Blazor apps consist of composable UI components implemented using Razor syntax (HTML, CSS, and C#). Blazor framework comes with two models: 1) server-side hosting model and 2) client-side hosting model.

In the server-side hosting model, Blazor is executed on the server from within an ASP.NET Core app.

In the client-side model, the Blazor app, its dependencies, and the .NET runtime are downloaded to the browser, and the app is executed directly on the browser. The coolest thing is that you do not need to install any add-on on the browser for the application to run. The Blazor app can run on the browser without the need of Javascript.

To create new app, choose ‘Blazor App’ template as below:

Compile/deploy:

According to Microsoft, .NET Core now builds executables by default. This is new in .NET Core 3. When using ‘dotnet build’ or ‘dotnet publish’, you can generate executable file matching the current environment or using command ‘dotnet publish -r <RID> –self-contained false’ to generate executable file matching a specific environment. To run the app, you can double-click on the file or launch it by from the command prompt directly.

Single-file executable is also a cool feature in .NET Core 3. Now you can easily build a single EXE file that contains the entire application. You do not need a specific framework installed as well. Now developers can build their app under one EXE file and anyone can use that file to run it on their own machines. All the redundant .dll files or any other assemblies are not seen anymore.

 

Many more interesting features:

  • High performance JSON APIs
  • The garbage collector uses less memory
  • .NET Standard 2.1
  • Linux improvements
  • Security improvements
  • Update new SingalR code
  • More

What’s new in C# 8?

Many new patterns are introduced in C# 8. Below are some of the outstanding one you should consider to use in your applications to enhance the performance and code optimization.

Ranges, indexes:

Index is a new type that describes an array index (starting from 0). Especially, with the prefix ^, the index counts from the end. Examples for both cases are below.

Index i1 = 0; 
Index i2 = ^1; 
int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 
// a[i1] = 0, a[i2] = 9;

With two Index values, we can create Range is a new type

var arr1 = [1..4];
var arr2 = [^2..^0];

Nullable reference types

When this feature is enabled, the compiler enforces null-checking at compile time to make sure that you’ve correctly checked all the null references. To enable this feature in your project, adjust the following property:

<PropertyGroup>
  <Nullable>enable</Nullable>
</PropertyGroup>

string? str = null;
Console.Writeline($”str[0]”); // you will get the warning because str may be null

string? str = null;
if (str != null) {
   Console.Writeline($”str[0]”); // the checking will remove the warning
}

Async streams:

This feature allows you to await upon foreach. Look at the example below, getQueriesAsync must be a method that is declared with async modifier and return an IAsyncEnumerable<T>. This method contains yield return statements to return successive elements in the asynchronous stream. After that, in order to consume that method, you need to add await keyword before foreach like below to loop through the elements of the stream.

await foreach(var query in getQueriesAsync(filter)
{
   Console.WriteLine(query);
}

Many more interesting features:

  • Switch expressions
  • Recursive patterns
  • IEEE Floating-point improvements
  • Default implementations
  • More patterns

You can see the full list here:

https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8

What’s next?

If you want to know the full list of new features in .NET Core 3. You can dig into more details by following the links in the references section below.

By releasing this generation of .NET Core, Microsoft strongly believed it is a stable and ready-to-use version of .NET Core and recommended many businesses that they can now confidently use .NET Core 3 in their premises. But the future in the .NET family is .NET 5 which will be expected to be release in late 2020. Therefore, the roadmap of .NET will .NET 5, 6, 7, not .NET Core anymore. You do not have to worry about the compatibility between .NET Core 3 and .NET 5 much. Because .NET 5 is expected to be a unified platform of .NET framework and .NET Core.and targeting Windows, Linux, macOS, iOS, Android, and more.

References

https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0

https://docs.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-3.0?view=aspnetcore-3.1

https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8