.NET5

What is .Net5 and Should You Migrate to .Net5 Considering its Benefits?

Microsoft announced the end of .Net5 during Build 2019 and that it would arrive in 2020. This will be the next huge release after the .Net Framework latest version 4.8. In the last 17 years, Microsoft has added hundreds of thousands of new features to its .Net Framework, which is 17 years old. .Net Framework […]

03 Aug, 2021 | Web Development

What is .Net5 and Should You Migrate to .Net5 Considering its Benefits?

Microsoft announced the end of .Net5 during Build 2019 and that it would arrive in 2020. This will be the next huge release after the .Net Framework latest version 4.8.

In the last 17 years, Microsoft has added hundreds of thousands of new features to its .Net Framework, which is 17 years old. .Net Framework gets incredibly heavy as a result of all these apps. Therefore, there is less scope to innovate with the .Net Framework. Furthermore, .Net Core has recently been introduced. It aimed to be a Linux and Mac alternative to the .Net framework at the time. By providing a bridge to .Net Framework 6, .Net Core 3 will empower WPF, Windows Forms, and Entity Framework 6.

.Net Core and .Net Framework are both new versions of .Net. Microsoft also announced .Net5, the next version of .Net. As part of the announcement, Microsoft mentioned that Windows 10 will utilize the .Net5 Framework, which has the advantages of open-source and cross-platform, instead of the .Net Framework, .Net Core, and Xamarin suites.

What is .Net 5

.net 5 platform

Developers will be able to build cross-platform applications using .NET5, the successor to .NET Core 3.1 and .NET Framework 4.8. With it, fragmentation in the .NET universe has been brought under control and new amazing features added. Even though you can’t learn everything about .NET5 at once, you can look at five key aspects to gain a clear understanding.

The Unified Platform

The first thing you need to know about .NET5 is that it brings you a new unified vision of the .NET world.

Working with .NET since its first release in 2002, you may be aware of its platform fragmentation. 

As ECMA 335, the .NET Framework runtime specification was initially developed for Windows, but it was standardized as a Common Language Infrastructure (CLI).

Any implementation of the .NET runtime could be created thanks to the standardization. Several appeared on the horizon at the same time: Mono for Linux, Silverlight for browser-based applications, .NET Compact and Micro for mobile devices with limited resources, etc. .NET Core is Microsoft’s cross-platform solution written from scratch.

Learn about the difference between .NET Core and .NET Framework here

The different implementations of .NET raised the question of where a package could run. To distribute your library, should you build different versions? .NET Standard is a formal specification of the APIs you should expect across CLI implementations, so it was the best answer to this question. By building your library for a specific .NET Standard, you will receive an assurance that it will work with every runtime that implements that standard.

As you realize, achieving the desired cross-implementation compatibility is quite challenging in this chaotic environment. The result is the appearance of .NET5.

.NET 5 – Original plan

It was announced that Microsoft plans to release .NET5.0 Preview 1 in March 2020.

ASP.NET Core, Windows Forms, WPF, UWP, Xamarin, and Blazor would all be unified into a single .NET platform equipped with unified base class libraries (BCL).

If this concept is adopted, .NET can be used for all kinds of applications. Windows desktop development, Android development, and iOS development could be integrated into a single native device project. In a Blazor project, applications could run in a browser, on a mobile device, or in a desktop application.

The focus would remain on performance: faster algorithms, an improved just-in-time (JIT) compiler and garbage collector, smaller executables to improve startup times, and so on.

Microsoft Build will Feature Updates on .NET 5

Microsoft Build will Feature Updates on .NET 5

A few changes have been made to Microsoft’s original plans for .NET5, announced at Microsoft Build in May 2020.

A global health pandemic delayed .NET 6’s unification of all the runtimes to November 2021 due to the ongoing pandemic. The .NET Core 3.1 update will focus on improving (performance) of .NET5 in November 2020.

New target frameworks in .NET5

The updated target framework version approach in .NET5 is prepared for the runtime unification in .NET 6. A project is identified by a set of API namespaces (TFMs), i.e. short code-names which specify the APIs a project is targeting. Any new .csproj project file created using the SDK looks like this:

<PropertyGroup>  <TargetFramework>netcoreapp3.1</TargetFramework></PropertyGroup>

There was a separate TFM for each .NET runtime before .NET5, such as netcoreapp3.1 for .NET Core 3.1 and net48 for .NET framework 4.8. TFMs for the .NET Standard 2.1, for example, are called netstandard2.1. The latter was necessary for libraries that are shared among multiple runtimes, such as .NET Core and Xamarin.

.NET5 only supports net5.0 as a TFM. It uses the net prefix instead of netcoreapp because there is only one version of .NET that is still under development. In addition to that, .NET Core 3.1 has also been renamed to .NET5.

Also known as the net5.0 TFM, the netstandard TFM is the successor. .NET Standard versions that define APIs that are common to multiple runtimes are no longer required since there is only one .NET runtime left. When Xamarin runs on top of this new unified runtime for .NET 6 and the full set of APIs for .NET5 became available, it will be able to run on all application models, including .NET5.

.NET Core libraries are consumed by all application models, which is what you’d expect.

The APIs provided by .NET5 can be enhanced by application models that target specific operating systems. TFMs are composed of prefixes that define the core .NET APIs and postfixes that indicate which operating system additional APIs target, for example:

  • With net5.0-windows you can create new Windows APIs, such as WinForms or WPF.
  • After the runtime unification, net6.0-ios will provide APIs specific to the iOS operating system. As part of Xamarin, these are currently available.

TFMs are not required for all supported operating systems. In these cases (current examples are Linux and WebAssembly), the .NET runtime prefix (e.g. net5.0) is used instead.

Learn about the Why ASP.Net is best for Microservices.

Single file applications

An updated publish type in .NET5 makes it possible to embed the entire application (including the .NET runtime) in a single distribution file. Linux is the only operating system that fully supports this feature.

MacOS and Windows didn’t achieve complete single-file support. During runtime, an additional file is required. This can be included as part of a single distributable file (not recommended for general use), but is extracted as separate files when the application begins.

The feature will be further developed and refined in future releases of .NET.

Performance improvements in .NET5

In order to achieve a more consistent performance, much work must be done. Basically, it is calculated by measuring latency using the 95th percentile of latency, which means 95% of requests are below this value. This metric is largely determined by the RyuJIT compiler and garbage collector:

  • By not optimizing a method the first time it is compiled, the tiered compilation allows for faster initial compilation. When recompiling frequently used methods, additional optimizations can improve their quality. Call counting is used in .NET5 to identify such methods. Because looping methods have a high impact even if they are called once, they are given special treatment by being optimized immediately.
  • The RyuJIT code generation engine has a number of other improvements. Hardware intrinsics, i.e. supporting certain instruction sets (e.g. SSE and AVX), are a special category of these improvements.
  • Garbage collector enhancements reduce the duration of pauses for applications while garbage collection is running, as well as optimizing the search for candidates for garbage collection.
what is new in .Net5

The following APIs are being optimized to enhance performance in addition to the above:

  • HTML 1.1 and HTTP/2 implementation,
  • The use of regular expressions
  • You can operate on strings.

Support for cloud-native technologies

We have made several changes to improve container workload performance:

  • In containerized environments, .NET performs better overall.
  • Image size reduction and a larger selection of images available.
  • Orchestration APIs, like OpenTelemetry, could be supported to make .NET easier to use in environments such as these.

ARM64 support

In addition to the x64 version, .NET Core 3.1 is already available on Linux ARM64. However, it fell short in terms of performance. This has been changed in .NET5 through several important investments:

  • Optimized JIT (just-in-time) compilers for ARM64.
  • The hardware intrinsics of ARM64 are supported, as are specialized instructions sets.
  • Algorithms tailored to the ARM64 architecture.

Windows ARM64 wasn’t supported natively in .NET Core 3.1, so it could only run x86 emulation code on these devices. Native support for Windows ARM64 is provided in .NET5, both for development and for deployment of applications (on devices such as the Surface Pro X).. Microsoft has not included the desktop component (Windows Forms and WPF) in the initial release. plans to add it in a future update.

 ASP.NET Core

In ASP.NET Core, not many changes have been made.

Due to the newly supported HPack header compression, Kestrel will provide performance improvements for HTTP/2. Furthermore, the application can be bound to new endpoints without the need to restart it if the configuration changes.

It is possible to run code before or after Hub methods using SignalR Hub filters. For HTTP requests, middleware works in the same way.

It still runs on Mono, but the Blazor WebAssembly now uses .NET libraries which makes it more compatible until the common .NET runtime is implemented in .NET 6. Additionally, Blazor WebAssembly 3.2 performed considerably better than Blazor WebAssembly 3.2.1.

Entity Framework Core

Despite being released at the same time as .NET 5, Entity Framework Core 5.0 is technically separate. .NET Standard 2.1 and .NET Core 3.1 are fully compatible with the library, as it is distributed as standalone NuGet packages. The new Entity Framework Core 3.0 differs from Entity Framework Core 3.0, which ensures compatibility with .NET Standard 2.0 and can even be used with the .NET Framework.

A majority of Entity Framework Core 5.0’s improvements can be categorized into two categories:

  • Generates better queries and works in more situations with SQL query generation.
  • If a database model is described in code, there are more options available.

Language Updates

There are a few changes in the languages that are supported by .NET 5 as well:

  • The new features in C# 9 make immutable data structures easier to work with and make code more concise overall. It comes with a new record type, as well as further improvements to pattern matching.
  • With F# 5, Jupyter notebooks will have even more interaction and analysis options.
  • There will be no further development of Visual Basic. The number of project types worked with Visual Basic in .NET 5 increased: Windows Forms, WPF, and Class Library applications, along with Console applications which had already been supported in .NET Core 3.1. This will facilitate the porting of Visual Basic-based .NET framework applications. It will not be possible to support new .NET Core features with Visual Basic in the absence of a language change.
.net 5 migration

C# Source Generators

Source generators in C# are associated with both .NET 5 and Language Enhancements, although they are not necessarily part of either. C# gains meta-programming support through this Roslyn compiler feature. Although source generators do not have access to application code, they can generate additional C# source files that will be compiled as part of the final compilation. The INotifyPropertyChanged interface can be automatically implemented using this technique in many cases, replacing Reflection calls at runtime and inter-library weaving.

Getting started with .NET 5

Since November 10th 2020, .NET 5 is generally available. Now is a good time to start using it!

.NET 5 can be downloaded from the .NET site. VS Code Extension for C# is compatible with any version of Visual Studio 2019 16.8 or later, as well as Visual Studio for Mac.

.NET 5.0 Preview 1 continues to run 50% of the load on Microsoft’s .NET website as an additional assurance of .NET 5 quality. They can get realistic performance data by using this method right from the start. At least one of the runtimes it was served by can always be seen in the footer of the website. Since then, it has always been .NET 5. If you reloaded the page just a few times, you would hit the .NET 5 runtime sooner rather than later. 

Other Vital Features to Highlight of .Net5

In addition to new APIs, new desktop apps, runtime capabilities, language support, and more, .Net 5 will fix all the bugs in the latest version of .Net.

1. Desktop Development with .Net5

In order to support desktop apps, Microsoft is fetching Windows Desktop Packs. A host of key desktop development tools will be included in .Net5. The four main desktop platforms are Xamarin, WPF, Windows Forms, and UWP (Universal Windows Platform). Windows desktop apps can be ported to .Net Core, but they add some benefits such as enhanced API performance, and easier deployments. ADO.Net and Entity Framework are some of the major sub-frameworks for desktop development in .Net5.

2. Mobile Development with .Net

In addition to .Net5, Xamarin will continue to support Android, iOS, tvOS, macOS, and watchOS platforms. Xamarin runs on the Mono runtime and offers a set of programming languages, developers’ tools, and libraries. C# is the backend programming language used by Xamarin. The main UI programming language for Xamarin is XAML.

3. Cloud Development with .NET5

.Net5 will include the capability to develop Azure apps. Developers will be able to create software on Azure with the release of .Net 4.5. As part of Azure Cloud development, users can leverage multiple technology frameworks and tools, such as Web API, ASP.Net, Serverless, Azure databases, Docker containers, microservices, and DevOps.

Cloud Development with .NET5

4. Game Development with .Net 5

For mobile, Xbox and other gaming platforms, .Net 5 and Visual Studio 2019 will support Unity, a crucial component of .Net gaming.

5. Runtime and Language with .Net 5

CoreCLR and Mono will be the runtime choices for developers with .Net 5. For Windows desktop, IOT, machine learning, and cloud applications, CoreCLR is the runtime used by .Net core. Mono is an open source .Net framework that implements Cross-Platform .Net. There are many similarities between Mono and CoreCLR, as well as some useful differences. In addition to this, .Net 5 will feature AoT (Ahead-of-Time) and JIT (Just-in-Time) compilation modes. JIT’s enhanced performance has been demonstrated on servers/desktops as well as in development environments. AoT is smaller, faster to start, and uses less memory than traditional computing techniques. 

Microsoft’s .Net 5 will be the largest version it has ever released due to all these updates and features. The changes that .Net 5 will bring to developers are still a mystery. The feedback Microsoft receives on its proposed updates is very important to its future course.

timeline of .Net5

Is The Migration/Upgrade Complex and Tedious?  

Well, it is subjective and depends on the individual case. The question you need to ask is how many of the features and properties your applications are dependent on will hinder the migration process or even prevent it from happening? Another important decision to make when upgrading and migrating is what .NET platform you plan to use. Migration from .NET Framework to .NET 5 will be fairly easy compared to migration from .NET Core. 

Nevertheless, the upgrade is free to use (from a runtime / framework perspective). Your only cost will be time and effort, which again depends on the version of .NET your application uses. Additionally, Windows Server 2007 and 2008 versions can be upgraded. Keeping an eye on your existing server is the only thing you need to know, as migrating from an old server will only make things more difficult. 

Read about the Front End Development Trends 2021, here in the article.

Benefits of Migration

Global Assembly Cache

It was believed that the .NET libraries could be centralized and centralized in the Global Assembly Cache (GAC). 

Different versions of libraries could be stored, unlike Component Object Models (COMs). In addition, Windows Vista offers additional security and requires an activation code. 

Remoting

A number of IIS components and Java Remoting contributed to .NET Remoting’s development. One application could manipulate real objects running inside other applications with the aid of an object. Due to the difficulty in using it correctly, it was not popular. 

There has never been a version of .NET core that supports remoting. As a result, it has inoperable placeholders that have been marked as obsolete and will be removed soon. 

Code Access Security 

.NET Core’s APIs were copied from the .NET Framework technology of Code Access Security. The Single Internet Information Server was used to host different applications during the .NET framework era. CAS was created in order to limit the potential damage. 

A risk indicator would be added to APIs to indicate how risky they are. A browser-hosted application is also a use of CAS. The implementation of CAS was hard, as it was with earlier technologies. IIS trust levels were ignored for several browser-hosted applications later on.  

Thread Abort

It was never possible to abort a thread in .NET Core. CancellationToken was adopted as an alternative to Thread at the time of the creation of ASP.NET. Terminate. The capabilities of .NET core have been expanded. Application frameworks other than Thread are not required. PlatformNotSupportedException was used even after the abort. 

Modifications to Public Contract

Several changes are disallowed since they violate backward compatibility created with an older API so that it does not need to be recompiled in order to perform its functions. In the case of types implemented by base types, there are several symbols used to add and remove interfaces from a type. 

New Target Frameworks in .NET5

There were different TFMs for every .NET runtime before .NET5. .NET framework 4.8, for example, net48. TFM remains net 5.0 with .NET 5. Since .NET Core is the only version that is still being developed, the prefix is used instead of .NET Core. Additionally, the TFMs for .NET 5.0 are the successors to those for .NET standards. It is unnecessary to create new and separate versions of the .NET standard to define what APIs are available across different runtimes because there is a single .NET running time. 

Application models consume the regular .NET Core libraries. Additional APIs are available when an operating system is targeted along with the full set of .NET5 APIs. A TFM consists of a prefix that specifies the APIs and a postfix that identifies the targets.  

Single File Applications

With .NET 5, an output method for displaying an application was introduced. Linux is supported for this feature. A Windows or Mac executable file needs additional files to run. There is an option to add extra files to the single distributable file, but they must be extracted individually when the application is launched. 

Performance Improvements in .NET5

By avoiding performing different optimizations for each method on the initial compilation, the tiered compilation approach allows for faster initial compilation. By adding additional customization, methods are recompiled with a higher quality. Call counting identifies these methods. 

WHEN and WHY to Migrate?

migrate to .Net5

According to my opinion, now is the right time. It is not necessary to wait until .NET 6 to get started with migrations. By starting early, you will have plenty of time to resolve any issues that arise. The more you delay the migration/upgrade, the more technical debt you’ll incur, since .NET 5 is inevitable. 

As part of the .NET Unification journey, you should see .NET 5 as one of the first steps, taking all those legacy programs and deciding what can be updated and ported over, and what should be replaced. 

Let me chalk down the process for easier migration:

a.) ASSESS YOUR APPLICATIONS – determine which of your applications use .NET Framework and .NET Core so you can meticulously and efficiently migrate to this upgrade. 

B.) CONSULT Stakeholders – It’s always advisable to seek help from your stakeholders if you’re considering rewriting your applications. Developers are more likely to move forward once a green signal is received. 

c.) FORM A PLAN – Keep tabs on the old .NET Framework and .NET Core cycles so you can develop a plan to make migration easier. 

.Net5 Roadmap

.NET 5 roadmap

This is the first major update to .NET since .NET Core was released in 2016. Microsoft has enormously innovated and this was inevitable. The product will be further enhanced as time goes on, adding runtimes, frameworks, etc. 

This is not long-term supported (LTS). As part of its plans, Microsoft plans to introduce new releases every year in November to enhance various layers of the product, including language, runtime, compilers, and tools. 

What’s the Future? 

.Net 6

This version of .NET 6 is of particular interest to me because of what it holds. My favorite feature is the .NET MAUI. An UI framework that can be used to build a UI on any platform, including mobile and desktop.

With Apple Silicon support, Microsoft is extending its support of .NET to Macs. Along with .NET 6’s November release, .NET 5 will bring cross-platform developers an array of new features. .NET will benefit from this unification in terms of expandable capabilities and utilities, while at the same time remaining simple. 

For companies coming from the .NET Framework, there are cross-platform development opportunities, reduced memory footprints, performance improvements, simpler project files, quicker startup, and better team-based development support. 

If mono were an option and not a requirement for WebAssembly and Xamarin development, we wouldn’t have to worry about .NET Framework Legacy. The performance of .NET Core has improved with each release, and Microsoft is likely to continue the trend. Additionally, .NET 5 would see CoreCLR leveraging monokey technologies that can minimize startup time for some applications, such as games, embedded devices, and iOS.

Start Migration

which one to use .net 5 or .net 6

.NET Standard 2.0 is the most important thing to migrate code to. It is now time to bring together mono and .NET Core for .NET 5, as well as provide a .NET Framework code roadmap to move forward. 

With .NET 5, utilities and capabilities will become more expansive and wider. With the new version of .NET 5, all new features and development capabilities would be included. 

Prefix, Stackify’s free Dynamic Code Profiler for Visual Studio, can simplify the migration to .NET 5 by finding hidden exceptions in your code and validating its behavior.  

Managing Existing .NET Core Projects

It will be easier to interpret the .NET Core path forward if we group existing .NET Core projects.

Versions on which projects are not supported

The decision is simple for those who have projects built on .NET Core 1.0, 1.1, 2.0, 2.2, or 3.0 – upgrade to .NET 5. Getting to a supported version NOW is the minimum you should strive for if you can’t get all the way there. It is easy to understand and detailed migration documentation has been provided even for complex projects.

You should consider the options available to you and evaluate your plans if you find yourself in such a situation. Support is still available for the following versions as of November 12, 2020.

  • (Legacy until August 2021)
  • Supported until December 2022 (.NET Core 3.1)
  • Microsoft .NET 5.0 (Deliverable until *February 2022)

Using this information, you should review how your existing project was left behind on a non-supported version. Were there misunderstandings? Budget or time constraints? In answering this question, we might be able to determine the best way forward. It may be a better idea to use .NET Core 3.1 if future support cannot be assured.

All Other Projects

.NET 5.0 provides significant improvements in project management, so following a successful migration to a current version is fairly straightforward. The earliest you can move to .NET 5.0, the better. You will benefit in the long run from performance gains, bug fixes, and more.

Existing .NET Framework Projects

Remember, the underlying Operating System dictates the support lifecycle of the .NET Framework. This provides support through 2029 and beyond for Windows Server 2019. Regardless of the transition plan, we have a long runway following this support cycle, and it might depend on the application type.

Infrequently Changed Applications

Projects with low churn rates most often benefit from less maintenance because they don’t need to do it all the time. The .NET Framework is often an excellent choice in these situations until a major change is required to provide business value in transition.

WPF, WinForms, and MVC Projects

Projects of the above types have .NET equivalents to their existing .NET frameworks, even though there are no “one-click” transition processes. The transition can also be completed by following documented suggested paths. Other items can also be problematic, such as dependency issues, third-party components, etc.

It is almost certain that these projects will perform better under .NET and will allow for the latest technologies to be utilized. As a suggestion, I recommend that customers analyze the effort involved in completing the transition as soon as possible and coordinate implementation with a planned major change. The migrated application needs extensive testing, so I recommend this.

WebForms Projects

Since the release of .NET Framework 1.0, WebForm projects have been an integral part of the framework; they won’t disappear by themselves. This project’s transition from Classic ASP to .NET is similar to that of the ASP to .NET transition. The Microsoft documentation of WebForms is still available and an alternative may be Razor Pages.

Until there is a valid reason for a complete rewrite, I don’t see a real urgency to upgrade WebForms to .NET until support is assured until at least 2029. Transitions are triggered by clients’ requests to refresh their accounts three and five years after the age limit. Our members who are not ready to transition are not being pushed back. WebForms development doesn’t greatly benefit from these new features, since the new features won’t change the development paradigm and are largely irrelevant.

I extend this concept to my work with the DNN Platform open-source project as well. We cannot afford the transition costs, so we are focusing on being the best we can with the available tools.

New Projects

I’m always open to new projects, no matter what. Any new projects will be in .NET 5 as long as there are no compelling reasons to use anything else.

Reusable Libraries – .NET Standard

Isn’t it true that for every rule, there is an exception? .NET Standard is used to bridge the gap between both platforms, so I would be remiss if I didn’t include it in my summary. A variety of versions of the .NET Standard are supported by both the .NET Framework and .NET. In its highest version, the .NET Framework sticks to the 2.0 .NET Standard, whereas .NET 5 adheres to 2.1 .NET Standard. .NET Standard 2.0, supporting .NET Framework and .NET Core! Just use this to create a Class Library! The following is Microsoft’s documentation that emphasizes that fact.

Consider both the reach and the feature set of your reusable libraries if you plan to distribute them on NuGet. .NET Framework 2.0 supports .NET Standard 2.0, which offers a fairly large number of features and a good reach. You shouldn’t be targeting the .NET Standard 1.x version, as you’d limit the number of features that are available.

The .NET standard 2.1 or the .NET 5 would do if you don’t need to support .NET Framework. It is recommended that you skip .NET Standard 2.1 in favor of .NET 5. .NET Standard 2.0 and .NET 5 will be the most widely used libraries. When you support .NET Standard 2.0, you can reach the widest audience and if you support .NET 5, you can leverage the latest .NET platform features.

Having the possibility of continuing to develop items supporting new technology while still supporting older technology is a good thing.

Conclusion

Though .NET 5 is not an LTS (Long-Term Support) release like .NET Core 3.1, it is still recommended that you upgrade existing .NET Core 3.1 projects to get access to additional performance improvements before upgrading to .NET 6 LTS next year.

The ongoing pandemic has delayed the release of .NET 5 which still won’t unify all the .NET runtimes like originally planned. In spite of that, it still brings many improvements, especially in terms of performance.

Are you looking for a product-development team that can communicate clearly, meet deadlines, and deliver the best possible results? Take advantage of TechnoBrain’s user interface and UX services. With our team of designers, we can assist you in building an engaging interface quickly and easily. 

The cornerstone of our market-leading cloud computing services is our expertise in the most popular cloud computing models. We offer expertise in Public, Private, Hybrid, and Multi-cloud deployment. You can select the optimal type of ownership, size, and access to your cloud infrastructure.

Client-oriented, customer-centric, and delivering tangible business results, TechnoBrain’s web developers help brands stay ahead as the digital landscape changes. Bring more value to your users and more profit to your business. A one-stop solution for all your web development needs.