Microsoft has emerged with a new innovation called .NET 5 wherein it provides a cross-platform development experience overcoming the previous fragmentations in the .NET world. This comes as part of Microsoft’s direct strategy to unify and simplify .NET platform as a result of listening to their customer’s needs.
.NET 5 is the natural development and evolution of the .NET Core 3.1 and .NET 4.6 framework. This is a great transition as .NET framework and .NET standard will cease to exist (which have been posing a lot of difficulties to .NET developers in the past). This makes .NET 5 is step towards single platform to develop dynamic applications across all devices, right form mobile and desktop apps (Xamarin/WPF), to front-end web development (Blazor), including REST (ASP.NET), Gaming (Unity), gRPC and web sockets (SignalR), AI Apps (ML.NET, .NET for Apache Spark) and Quantum programming (Q#). You can download .NET 5.0, for Windows, macOS, and Linux, for x86, x64, Arm32, Arm64. You will still be able to use .NET Framework with old operating systems but with Microsoft decreasing its life support cycle, it may be terminated sooner than expected.
So, what does this sharp turn in .NET 5 evolution mean to .NET developers and customers? We will explore that in this article.
.NET 5.0 is the first release in our .NET unification journey. .NET 5.0 is a current release. That means that it will be supported for three months after .NET 6.0 is released. As a result, we expect to support .NET 5.0 through the middle of February 2022. .NET 6.0 will be an LTS release and will be supported for three years, just like .NET Core 3.1.
Image source: https://devblogs.microsoft.com/dotnet/introducing-net-5/.
Top 7 New Features of .NET 5
One of the key underscoring features of .NET 5 is its ability to target cross-platforms from iOS, Mac OS, Windows, WatchOS, Android, tvOS etc. This new release focuses on the improvements from .NET 3.1 and prepares for delivering better performance.
C# 9 and F# 5 are part of the .NET 5.0 release and included in the .NET 5.0 SDK. Visual Basic is also included in the 5.0 SDK. It does not include language changes, but has improvements to support the Visual Basic Application Framework on .NET Core. There have been several upgradations and added features from the older version of .NET Framework. Let me take you through how these upgrades overcome few challenges faced in the previous platforms. For complete list of new features refer to What’s new in .NET 5 | Microsoft Docs
1.) Support for Windows Arm64
This is a significant improvement from the previous .NET 3.1 platform. .NET 3.1 rendered support to Linux ARM64 but was lacking in the performance department and there wasn’t any native support given to Windows ARM64. In the previous .NET 3.1 Framework, one could optimize methods using x64/x86 intrinsics. But unfortunately, systems that couldn’t run using these intrinsics performed below par and delivered slower performance levels. Hence, this new update is a sigh of relief for you .NET developers, wherein this update intrinsics will afford better performance yield across ARM architecture. For example, by providing native support to Windows ARM64, Windows Forms, WPF applications will be able to run on devices like Surface X Pro.
Microsoft invested delivering improvements in this arena:
a.) .NET 5 provides JIT improvements (just-in-time) and optimizations for ARM64.
b.) Provides specialized instruction sets to support ARM64
c.) Detrimental algorithms for customized performance.
2.) Single File Applications
Great addition to .NET 5. This is, I believe, is an attractive upgrade for any application developer. Single file applications are deployed as a single file which includes the file and all its dependencies (including .NET runtime). Single file applications were available in .NET 3 Framework as well but however, it has been optimized and enhanced in .NET 5. Previously in .NET Core 3.0, when a user ran the single application, the core host would extract all the files tentatively to a directory. But, with this new upgrade, the extraction is no longer required.
Single File deployment is available for both the framework-dependent deployment model and self-contained applications.
3.) App Trimming
One of the big differences between .NET Core and .NET Framework is that .NET Core supports self-contained deployment – everything needed to run the application is bundled together. It doesn’t depend on having the framework separately installed. From an application developer perspective, this means that you know exactly which version of the runtime is being used, and the installation/setup is easier. The downside is the size – it pulls along a complete copy of the runtime & framework.
To resolve the size problem, Microsoft earlier supported an option to trim unused assemblies as part of publishing self-contained applications. In .NET 5, Microsoft has taken this further by cracking open the assemblies and removing the types and members that are not used by the application. This further reduces the size.
4.) Support for C# 9
.NET 5 application developers will have access to the new capabilities of C# 9. Some of the key features include pattern matching, record, top-level statements etc. For instance, in Records, a with expression has been introduced which is essentially a reference type that produces no copy when passed to member functions. Records are perfect for people working with data. The flexibility of a class, and the pragmatism of a struct. This omits the IEquatable implementation task, saving much time and energy for you!
In terms of, top-level statements, the Main has been omitted to make C# learning quicker and easier for adoption.
Some of the other enhancements includes:
a.) new keywords and, or and not.
b.) JSON enhancements makes the .NET framework more independent and closely tied with framework evolutions.
Overall, this has made the programming language efficient to implement and learn, saving .NET developers certain tedious tasks.
5.) Performance Enhancements
a.) The Garbage Collector (GC) has been made significantly more efficient in .NET 5 and has provisioned for better scaling for machines with more core count. Key GC improvements include:
1.) Optimize decommitting GC heap memory pages
2.) Expensive memory resetting is evaded
3.) GC has employed Vectorize sorting
4.) Significant time has been reduced for GC to close threads.
b.) Another enhancement in performance is the “Just In Time (JIT) compiler”, wherein it offers upgraded hardware intrinsics (e.g. SSE and AVX). Here, it renders support to particular instruction sets of selected processors.
c.).NET 5 offers an Ahead-of-Time (AOT) compiler alongside its JIT tooling to address the need of precompiled code for Web Assembly and mobile operating systems.
Lastly, there has been improvements in the .NET Compiler platform as well, with the introduction of C# Source Generators and Performance Focused Analyzers. For more details on .NET 5 performance improvements refer to Performance Improvements in .NET 5 | .NET Blog (microsoft.com)
6.) Cloud Native Support
In container workload situations, multiple enhancements have been implemented that improve the overall performance in cloud container environments. Furthermore, it pushed for a reduction in container image size which offers size savings and additionally, extends the option to select from a larger plethora of container images.
|SDK: 5.0||~280MB||~218 MB|
This is good news. With ASP.NET being provisioned, docker cloud image size will be significantly reduced by at least 40%. This could be done as a result of Microsoft terminating the build pack dependency (buildpack-deps). Lastly, in order to simplify the functionality of the .NET platform, the new update supports new container APIs as well ensuring faster and smoother operations overall.
In terms of Security in .NET 5, certain changes have been made around the usage of OpenSSl enabling support for TLS 1.3 on Linux. TLS 1.3 wasn’t available on Windows previously but now it’s been made a default. For more information on networking security, you can visit here.
Is The Migration/Upgrade Complex and Tedious?
Well, it is subjective and based on individual cases. You need to ask yourself and analyze how many of the features and properties your applications are dependent on that will hinder the process or even fail to migrate to the new .NET 5 update? Another important factor to consider when you intend to upgrade and migrate is to look at what .NET platform you are using. Because migration from .NET core to .NET 5 will be relatively easier than say from .NET Framework to .NET 5.
However, the good thing about the upgrade is that it is free of cost (from the runtime / framework perspective). Essentially, the only thing it will cost you is a lot of time and effort, which again, is reliant on the versions of .NET your applications use. Additionally, the upgrade is available on all versions of Windows servers. The only thing you need to keep an eye out for is the life cycle of your existing server because it will only make things more jarring and tedious to migrate from an old server.
WHEN and WHY to Migrate?
In my opinion, I’d say NOW. You don’t need to wait for .NET 6 to get started with migrations. The sooner you start, the better, giving you time to deal with any issues that may emerge. If you stall the upgrade/migration process, it only will complicate things and increase your Technical Debt for you as .NET 5 is inevitable.
You should see .NET 5 as a first step in .NET unification journey, one where you should start to take all that legacy code and decide what’s necessary to bring forward by porting and updating, and what needs to be completely replaced.
Let me chalk down the process for easier migration:
a.) ASSESS YOUR APPLICATIONS – analyze and assess which of your applications use .NET Framework and .NET Core so that you meticulously and efficiently migrate to this upgrade.
b.) CONSULT STAKEHOLDERS – It’s always better to consult your stakeholders regarding the transition to see if they’re willing to invest in re-writing applications. Once a green signal is received, it makes things easier for developers to move on from there.
c.) PAN OUT A PLAN – Keep tracking the cycle of the old .NET Framework and .NET Core and schedule a plan to simplify the migration process.
.Net 5 Roadmap
.NET 5 has been a major update since the introduction of .NET Core in 2016. This has considerably a major innovational leap by Microsoft and, an inevitable one. More features will be added in terms of runtime, framework etc. along with extending the product’s scope as time progresses.
.NET 5 isn’t long-term supported (LTS). Microsoft intends to introduce new releases every year in November to enhance various layers of the product in terms of language, runtime, compilers, and tools.
To know more about each feature’s implementation timeline, you can visit here.
What’s the Future?
What is especially intriguing to me is the new .NET 6 release and what it holds. One of the key features that I am looking forward to is .NET MAUI. It is a new framework that proposes a universal model for building UIs on mobile and desktop platforms.
Microsoft announced that it would extend its .NET support to Macs with Apple Silicon. .NET 5 in addition to this year’s .NET 6 November release, will offer a repertoire of developments for .NET developers and app developers across cross-platform ecosystems. This unification will afford .NET with expansive capabilities/utilities whilst still maintaining simplicity.
I see a bright future in the horizon wherein one can use .NET across different operating systems, devices or even chip architectures.
Rest assured; it is a game changer.
In an upcoming article, I will go deeper on .NET 5 Upgrade benefits, Migration challenges and recommended Upgrade process.