What's new in .NET 6?

06 december 2021 om 10:00 by ParTech Media - Post a comment

Microsoft .NET 6 came along with several preview releases and two release candidates this year. Each preview featured a different set of.NET 6 features for developing server/cloud, desktop, IoT, and mobile apps.

In this post, we will go through five such features that turned out to be quite so useful. So, let's get started right away.

Table of contents

  1. .NET 6 new Project Templates
  2. Package Validation Tooling
  3. .NET 6 Multi-platform App UI (MAUI)
  4. SDK Workloads
  5. Inner-Loop Performance
  6. Conclusion

.NET 6 new Project Templates

.NET 6 preview 7 included a number of new project templates, all of which are quite fascinating. In essence, these templates are based on the new C# 10 features. The templates are significantly more straightforward and easy to use. For example, when you create a console application henceforth, you will only get the below basic line -

This is fantastic news. It just makes more sense than getting all of the below for a single useful line of code (as it was previously) -

.NET 6 offers three new capabilities that make the above transition possible -

  • Top-level Statements - This functionality was available in C# 9. In a nutshell, you don't have to include the Main function manually in a console application project starting with C# 9. However, you may utilize the top-level statements feature instead. This drastically reduces the amount of code.

  • Global Usings - Every C# file began with a set of global ‘using’ that are required for any implementations. However, this isn't necessary. The keyword global is introduced in C# 10. You can define global ‘usings’ for the entire project in a separate file that contains these imports by using this keyword usings.cs. Other project files can be streamlined as a result of this. This is referred to by C# programmers as "vertical waste removal."

  • Implicit using directives – This option instructs the compiler to import a set of ‘usings’ based on the project type. In essence, an implicit set of global ‘using’ is created for each project type. As a result, you don’t have to declare them explicitly in each file. These are the ones for console applications:

Package Validation Tooling

Another interesting addition was package validation tooling. This functionality was introduced in.NET 6 previews 5, and it's an excellent example of an internal utility that can be distributed to all users. This means there is already technology in the dotnet/runtime repo that ensures that multi-targeted packages are well-formed.

During package development, package validation technology allows developers to ensure that their packages are consistent and well-formed. It allows developers to check packages against previous versions, framework versions, and runtime. This has been a major issue especially since the.NET ecosystem has grown (particularly with cross-targeting packages and new platforms where the community is not yet strong enough). With this technology, you can't develop a package that isn't validated, making the entire.NET ecosystem safer.

.NET 6 Multi-platform App UI (MAUI)

Microsoft has talked a lot about "huge unification" since .NET 5. In principle, the concept is pretty simple - .NET is used to target Windows, Linux, macOS, iOS, Android, tvOS, watchOS, and WebAssembly with a single version. They started this process with.NET 5, which resulted in a single.NET runtime and framework that can be used anywhere and has consistent runtime behaviors and developer experiences.

With.NET 6, they expand on this concept by including Xamarin, as well as Android and iOS, under the umbrella. .NET Multi-platform App UI (MAUI), a new UI toolkit built on top of Xamarin, was announced at Build 2020 by Microsoft. Of course, to some extent, this decision is influenced by the community. Many people have asked users to transfer code between their mobile and desktop apps. As a result, they can use.NET MAUI to create applications that operate on Android, iOS, macOS, and Windows using a single code base.

SDK Workloads

SDK workloads were originally introduced in the.NET 6 preview 4 release. This feature allows customers to install only the SDKs they need, rather than a full "all-in-one" SDK. So, if you only want to download and install ASP.NET Core or Xamarin, that's fine. This functionality is essentially a package manager for SDKs. All of this is made possible by the new workload CLI term.

This feature is also part of a larger narrative. There was a need for an all-in-one monolithic SDK when.NET Core was first developed. This is especially true for several of the capabilities in.NET Core 2.x and 3.x. However, as the.NET SDK's supported workloads expanded, a new requirement rose: a need for a tiny and focused SDK.

As previously stated, the CLI workload command supports this capability. It grew during the course of.NET 6 previews 4, 5, and 6.

Inner-Loop Performance

When a new version of the framework is released, you can assume that performance will improve. The same may be said for.NET.’s previous versions of the framework (as well as this one). .NET 6 focuses on enhancing inner-loop efficiency, such as the performance of the CLI, runtime, MSBuild, and so on. As a result, the focus is on improving the developer experience through streamlining tools and workflows.

Many other platforms do much better than.NET when it comes to typical inner-loop operations. This is particularly off-putting to newbies to.NET. There is a lot of information regarding some of the improvements from preview 2. Here is the complete list of improvements -

  • Improved performance of CLI/SDK/MSBuild that relates to the developer inner-loop.
  • Improved launch/debug/update loop
  • Hot Reload application changes during development inner-loop from the .NET CLI
  • Hot Reload for Blazor Components
  • Hot Reload for ASP.NET Core
  • ASP.NET Core Hot Restart

Final Words

.NET’s goal is to obtain as much feedback from the community as possible and then improve on it. Because it is expected to change, possibly in unexpected ways, preview features are opt-in. This is fantastic, and we believe this will become the norm in the future.