medilaser What’s New In .NET 5.0? | Desuvit

.NET 5.0 is Microsoft’s next major .NET Core release after 3.1. The company chose to name the new release .NET 5.0 instead of .NET Core 4.0 for two reasons. For one, they did not want users to confuse 4.x versions with the .NET Framework 4.x. Also, they eliminated ‘core’ from the name to highlight. NET’s primary implementation hereafter.

Compared to the .NET Core or .NET Framework, the new .NET 5.0 supports many more apps and platforms. .NET 5.0’s Release Candidate 1 launched on September 14, 2020. This new release brought the union between .NET Framework and .NET Core closer than before.

A Release Candidate 2, the final of two RCs, launched on October 13, 2020. However, the final official release of .NET 5.0 took place on November 10, 2020. That is the date when it became available to the general public. 

.netcore release history

You can download this from .NET 5.0 from dotnet Microsoft. 

Before that, though, you may have questions concerning the features of the new release. Well, this article will explain just what is different about .NET 5.0 to you. So read on to know more.

What .NET 5.0 Aims To Do

.NET 5.0’s primary purpose is to provide an integrated .NET SDK experience through a single BCL (base class library). The release aims to do this across all .NET 5.0 applications. To accomplish this, it relies on the support of native and web applications across several operating systems.

Just one .NET 5.0 native application project can support Microsoft Duo (Android), Windows, and even Apple iOS. It does this through native controls across these platforms.

Apart from that, .NET 5.0 has other high-level goals, including:

  • Support for creating high-performance cloud applications
  • Faster BCL algorithms
  • Improved support for runtime containers
  • Support for HTTP3

Going forward there will be one .NET and can be used as a target framework for Windows, Linux, macOS, iOS, Android, tvOS, watchOS and WebAssembly and more.

Other notable .NET 5.0 features are:

  • Half Type: A binary floating-point taking up 16 bits
  • Assembly Trimming: To reduce application sizes by trimming unused assemblies
  • Customized Trimming: Provide the trimmer with hints through attributes or with explicit directions through XML files
  • C# 9 Pattern Matching: For logical, relational, and simple type patterns 
  • ClickOnce Deployment: Enhanced ClickOnce deployment for Simple Windows Desktop application
  • Single file apps: bundling all the dependent files into a single binary file.

What .NET 5.0 Doesn’t Aim To Do

.NET 5.0 has a lot of high-level goals. However, there are a few things it does not do, and it is equally important to know what those are. So this section will cover those points.

It Doesn’t Replace .NET Framework

Going forth .NET’s primary implementation is going to be .NET 5.0. However, it will still support .NET Framework 4.x. As such, Microsoft has no plans to transport these technologies to .NET 5.0 from .NET Framework. However, the .NET 5.0 does have a few alternatives within itself:

Recommended alternatives in Net 5.0

It Doesn’t Replace .NET Standard.

Developers can designate the net5.0 target framework moniker (TFM) for any project of new application development. That applies to base class libraries as well. The process of sharing code across .NET 5.0 workloads is now exceedingly simple. After all, developers need nothing more than the net5.0 TFM for it.

The net5.0 Target Framework Moniker (TFM) also has a role to play in .NET 5.0 apps and libraries. Here, the TFM merges and switches the netstandard and netcoreapp TFMs. However, sharing code among .NET Core, .NET 5 workloads, and .NET Framework is slightly different. To do this, users need to designate netstandard2.0 as their TFM.

New .NET 5.0 Features

Microsoft’s .NET 5.0 has its fair share of improvements. This section will give you deeper insight into each of them. Before that, though, consider this overview of what is new in.NET 5.0, setting it apart from its predecessors:

  • Battle-tested: .NET 5.0 has already undergone severe testing after months of hosting at dot.net and Bing.com.
  • Better Performance: Several components in .NET 5.0 have seen significant performance improvements. 
  • Language Improvements: Both C# 9 and F# 5 come with a ton of upgrades. For instance, C# 9 offers top-level programs and records. At the same time, F# 5 provides a performance boost for functional programming and interactive programming.
  • .NET Libraries Improvements: .NET libraries now offer better performance for JSON serialization, HTTP (HTTP 1.1, HTTP/2), and regular expressions. Not to mention, they are entirely annotated for nullability.
  • Lowered P95 Latency: Refinements in the GC, tiered compilation, and other aspects have led to a drop in P95 latency.
  • Better Application Deployment Options: From ClickOnce client app publishing to single-file apps, there is a noticeable improvement in application deployment methods. Apart from that, .NET 5.0 also offers Server Core container images and reduced container image size.
  • Greater Platform Scope: .NET 5.0 offers an expanded platform scope through Windows Arm64 and WebAssembly.

Languages

.NET 5.0 and .NET 5.0 SDK come with C# 9 and F# 5. .NET 5.0 SDK also features Visual Basic, but this does not have any language changes. Instead, it comes with improvements to hold up the Visual Basic Application Framework on .NET Core.

C#9 Updates:

Updates to C# 9 offer the following benefits:

  • Record Types: Reference types with value-based equality semantics. Comparison with non-destructive mutation is also supported. Both are possible through a new ‘with’ expression.
  • Relational Pattern Matching: Pattern matching abilities expands to relational operators. In turn, this facilitates comparative evaluations and expressions, even logical patterns such as new keywords: ‘or,’ ‘and,’ and ‘not.’
  • Top-level Statements: Omission of the ‘Main’ method is possible to accelerate adoption and learning of C#. That, in turn, makes application as simple as System.Console.Write(“Hello city!”);
  • Function Pointers: These language constructs expose intermediate language (IL) opcodes like ldftn and calli.

For more details on the new features of C#9, refer to our previous blog here.

F# Updates:

F# is a well-known .NET functional programming language. Now, developers can make use of F# 5 through .NET 5.0. Here is its key feature:

Interpolated Strings: F# supports basic string interpolation as follows:

Interpolated Strings

Besides basic string interpolation, it offers typed interpolation. For the latter, a given type should match the format specifier, like:

string interpolation

This function is quite like the sprintf, which formats a string based on type-safe inputs.

Nullability Annotation Improvements

.NET libraries now offer complete annotation for nullability. So when you enable nullability, the platform offers you more type information to direct you in using the feature.

One thing to note, though, is that .NET docs are not yet completely annotated. For instance, String.Split(Char[]) will feature an annotation of char[]?.

That said, both System.Device.Gpio and Iot.Device.Bindings packages (versions 1.1.0) feature the new .NET 5.0 annotations. While the two libraries are multi-targeted, .NET 5.0 successfully produces annotations for all targets.

.NET 5.0 also comes with new annotation types. This is because large classes commonly embody object members in helper methods, typically called from a constructor. In such cases, the C# compiler cannot follow the call flow to the object assignment. Instead, it will assume that the member is null as it exits the constructor. As such, it will send a warning with CS8618. The new MemberNotNull attribute easily solves this issue.

All you need to do is apply the attribute to the helper method. The compiler then observes the value fixed by you and realizes that the method is a call from a  constructor. MemberNotNullWhen works similarly.

Remember, though, that when you enable nullability, older .NET Core 3.1 could create new diagnostics. This specifically happens when you retarget the code to .NET 5.0 because of the existence of new annotations.

  • Follow our tech founder for more valuable tips, tricks, learning, content and future opportunities

    Follow Here

Windows Forms Designer Updates

Features of the Windows Form Designer in .NET5.0

Both.NET Core 3.1 and .NET 5.0 have seen updates in their Windows Form designers through Visual Studio 16.8. Most notably, it can now support all the controls for Windows Forms. Apart from that, the Telerik UI for WinForms controls is also supported by the new designer. 

All the key functionalities expected in a designer are present which involve drag-and-drop, move and resize, cut/copy/paste/delete controls, selection, integration with properties Window, events generation, and much more.

.NET 5.0 Target Framework

In .Net 5.0, the way of using the target framework is changed. The below code snippet shows the new target framework representation for a project,

To access Windows desktop APIs, such as WPF, WinRT, or Windows Forms, you will need to target net5.0-windows. Operating system versions, like net5.0-windows10.0.17763.0 or net5.0-windows7, can be specified. Using WinRT APIs requires targeting a Windows 10 version.

net5.0 now permits the use of portable APIs, such as ASP.NET Core. As such, ASP.NET templates are now support .NET 5.0. 

Below is an overview of what’s new in the .NET 5.0 target framework:

  • .NET 5.0’s new Target Framework Moniker (TFM) is .net 5.0.
  • net5.0 unifies and replaces netstandard and netcoreapp TFMs.
  • net5.0 supports the .NET Framework compatibility mode.
  • net5.0-windows now exposes functionality specific to Windows, including WPF Windows Forms, and WinRT APIs.

WinRT Interop (Breaking Change)

.NET 5.0 now features a new model to support WinRT APIs. Here is what this new model offers:

  • Calling APIs in either direction (CLR <==> WinRT)
  • Collecting data between the two type systems
  • Unification of types, meant to be treated the same throughout the API boundary or type system (“projected types”; for instance: IEnumerable<T> and IIterable<T>)

.NET5.0’s .NET runtime no longer includes the previous WinRT interop system, a breaking change. As such, you cannot run apps and libraries using WinRT through .NET Core 3.x on .NET 5.0. Instead, you will need to rebuild them.

Henceforth, developers will use the new CsWinRT tool. This tool creates C#-based WinRT interop assemblies, deliverable through NuGet. Everyone wanting to expose .NET APIs to native code or native APIs to .NET can rely on the CsWinRT tool.

Logically, the tool is a lot like tlbimp and tlbexp, but better. While tlb tools depended on several COM interop plumbing in the .NET runtime, the CsWinRT tool depends only on public .NET APIs.

Here are the advantages that come with the new WinRT interop model:

  • Can be developed and enhanced separately from the .NET runtime
  • Symmetrical with  tool-based interop systems offered for other operating systems, including iOS and Android
  • Makes use of other .NET features, such as AOT, IL Linking, and C# features
  • Simplifies .NET runtime codebase
  • Does not need NuGet references to use WinRT APIs

Native Exports Updates

Exports for native binaries can now be called into .NET code. The foundation for this requires hosting API support for UnmanagedCallersOnlyAttribute. In turn, this foundation creates an experience of a higher level.

Here is what the  .NET Native exports project allows:

  • Works cross-platform
  • Does not need higher-level interop technology such as COM
  • Expose custom native exports
  • Already existing projects that permit such scenarios are Unmanaged Exports and DllExport.

Wrap Up

.NET 5.0 essentially offers users a single, unified platform for developing any kind of application. It is advisable to practice with .NET Core 3.1To get the most out of .NET 5.0 and its many unique features. 

The migration process will then be a lot smoother. So users can take full advantage of features like the C#, RyuJIT, server garbage collection, and more updates. If you need the help of a seasoned software development company, look no further! 

Desuvit’s primary concern is automated workflows and greater productivity for our customers. For a detailed project discussion, Contact us. We can and want to help you grow your business.

Desuvit is a Norway-born software development company delivering Custom Software Development, Mobile Apps, and Web Applications Development for various verticals and business domains. We offer end-to-end solutions for companies with no software or IT division, Startups, and companies that need to scale their software development efforts but lack the expertise required. We help our clients in growing their businesses so we can grow with them.

Some of the technologies we work with: .Net, Azure, Microservices, Azure functions(Serverless computing), React Native, Flutter, React JS, TypeScript, Angular, NServiceBus, Azure Service Bus, Azure Queues, SQL Service, MySQL, Cosmos DB, etc.

Contact Us Estimate Your Project

Enjoyed this article? Subscribe for more valuable and great content !

Enter your email address below to get new articles with valuable content delivered straight to your inbox, plus special subscriber-only content to help you with your next mobile app or software development project.

By subscribing, you agree with our privacy policy and our terms of service.