Microsoft is set to introduce .NET 6.0 in November 2021, but it has already offered us many preview releases in the past few months. Every preview revealed a range of .NET 6.0 features that help us develop web, desktop, server, cloud, mobile applications, and IoT. Before the release, we are predicting two more releases of the preview, which will offer us a new set of features.
Here, in this article, we have discussed 8 amazing features extracted from .NET 6.0 preview releases.
What’s New in .NET 6.0?
The new Microsoft .Net 6.0 may introduce capabilities for iOS, Android, and macOS, which are right now in the Xamarin .NET platform. The new release will also extend support for hybrid app development through Blazor, a web app development software. It will help create an app for different native UIs, combining mobile and desktop experiences.
Let’s explore all the features of .Net 6.0 that we know till now.
1. Project Templates
The .NET 6.0 preview offered a series of interesting project templates that are according to the C# 10’s new changes. Amazingly, these project templates are much simpler to use and cleaner to access.
For example, if you need to make a console application, then you can use the following:
// See https://aka.ms/new-console-template for more information Console.WriteLine("Hello, World!");
How did this happen?
using System; using System.Collections.Generic; using System.Linq; namespace SimpleConsoleApplication { public class Program { public static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }
This is because of the three amazing features of .NET 6.0:
- In C# 9, we use top-level statements and .NET 6.0 has introduced this feature for templates. This means that you don’t really need to use the Main method for your console application. You can only utilize top-level statements, which reduces the code we need to write.
- When you are using C#, you need to define usings at the starting of the implementation. It is known that these usings are many times redundant. Therefore, in C# 10, we can use the Global keyword to define every usings of the project in a different file. The creation of this file makes the implementation of other projects simpler. We are practically eliminating the vertical waste here.
- The last feature is implicit using directives that automatically find usings that are relevant for a project type. This means for every project, implicit usings are identified, which eliminates the need of externally defining each file.
using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Net.Http.Json;
2. Multi-Platform Application UI
Even before .NET 5.0 was launched, Microsoft dreamt of a unified .NET platform. A landscape where we can target Linux, Windows, iOS, macOS, tvOS, Android, WebAssembly, and watchOS. With the release of .NET 5.0, we saw a glimpse of this, as Microsoft unified its runtime.
In .NET 6.0, they included Xamarin to the list, which already has iOS and Android. In the Build 2020 event, Microsoft introduced .NET multi-platform app UI or commonly known as MAUI, which is a modern toolkit on Xamarin. The Microsoft community has asked for such an invention for a long time. Now, they would be able to use .NET MAUI to create apps that can be used in iOS, macOS, Android, and Windows from one code.
.NET 6.0 comes with a Base Class Library (BCL), which has a base for Android, macOS, iOS, and Windows; these frameworks use BCL to extract details. This means you don’t need to understand these key details for your code, it can be extracted from BCL.
3. Package Validation Tooling
The package validation tool is an important feature in .NET 6.0. in the runtime repo, we already have tools for the well-formation of multi-target packages. Package Validation tooling helps programmers evaluate and validate the well-formation and consistency when developing a package. This means developers can validate packages with the previous versions, including runtime and framework versions.
However, for now, you can use package validation tooling in the form of the MSBuild SDK Package.
- The first important package validation is knowing the compatible frameworks. For this, the tool catches issues in the pack time. This means the tool checks if the compiled code works with both frameworks. For example, we create code using dotnet pack, an error might occur because the compatibility of code is not apt with both .NET 5.0 and .NET 6.0.
public class TestClass { #if NET6_0_OR_GREATER public void DoStringManipulation(ReadOnlySpan<char> input) { // use spans to do string operations. } #endif public void DoStringManipulation(string input) { // Do some string operations. } }
- It is possible for us to put a dent in the behavior of our past packages. While everything may seem okay from the perspective of the code, you may receive a version of the package error. For example, making a binary breaking or breaking the Liskov Substitution Principle. Package validation tooling helps you find and address this issue.
<Project Sdk="Microsoft.NET.Sdk"> <Sdk Name="Microsoft.DotNet.PackageValidation" Version="1.0.0-preview.5.21302.8" /> <PropertyGroup> <TargetFrameworks>net6.0</TargetFrameworks> <PackageVersion>2.0.0</PackageVersion> <PackageValidationBaselineVersion>1.0.0</PackageValidationBaselineVersion> </PropertyGroup> </Project>
- The last package validation tooling benefit is in runtime errors. If you need to make your package execute on both Windows and Unix, then you need to write the code accordingly. But, if you have missed one parameter in the Unix function, an error will occur, which can be detected using package validation tooling.
public class TestClass { #if Unix public void DoSomething(string input, bool input2) { // Unix specific stuff } public void DoSomething(string input) { // Unix specific stuff } #else public void DoSomething(string input) { // Windows specific stuff } #endif }
4. Inner-Loop Performance
With the release of .NET 6.0, Microsoft will enhance the inner-loop performance, including runtime, CLI, MSBuild, etc. This means the focus will be on optimizing workflows and tools that improvise developer experience.
Some of the inner-loop improvements released with Microsoft .Net 6.0 are:
- Improve SDK, CLI, MSBuild performance.
- Modernized debug, launch, and update of Hot Reload app changes at the time of inner-loop.
- Hot Reload for both Blazor and ASP.NET Core.
- Reimplementation of the Razor compiler with source generators.
- BCL support for Hot Reload
- Decrease in EF Core App starts time with compiled models.
Definition: Hot Reload offers you the ability to make code changes in an app when it is running. With this, you are able to improve productivity, since you don’t need to halt everything to make changes.
5. SDK Workloads
In the .Net 6.0, we will receive the power of SDK workloads. This will allow us to use important SDK in place of all-in-one SDKs. For example, if you wish to use only Xamarin, you can achieve that.
When .NET was originally designed, there was a need for a monolithic SDK. However, with an increase in popularity of the .NET SDK workload, the requirement for a focussed SDK increased. Hence, these SDK workloads are designed to replace the old monolithic SDK, which had a huge distribution size and more build time.
With the help of new SDK workloads, we can create workloads and offer them independently from the SDK, and you can acquire these through the installation tool of your choice, such as Linux package manager, Visual Studio Installer, etc. In the long run, Microsoft is expecting all these workloads to work in this manner, as it will give a focused small SDK.
Simply put, SDK workloads act like a .NET SDK package manager.
The SDK feature additional uses dotnetworkload list and dotnetworkload update verbs. The list feature allows developers to find installed workloads and the update feature helps update every workload to the latest version.
You can check more details about SDK workloads on this link.
7. Dynamic PGO
To use profile-guided optimization, we need to understand the assumption that says the code used for execution in the start is uniform and it can deliver high performance. PGO helps us compile the code at a better quality. It rearranges application binaries and decreases the binary size of the code utilized in the starting.
.NET 6.0 will also help us use dynamic PGO which integrates PGO with the RyuJIT .NET just-in-time compiler to offer better performance.
8. W^X
W^X means write or execute. It is a security feature used in virtual machines and operating systems. It says that either every page in the address space will be executable or writable. If this is not present, then a program gains the power to write infrastructure to data memory and run these instructions.
.NET 6.0 will introduce this feature to restrict attack paths by preventing memory pages from executing and writing at once.
How does this works?
In the runtime, we now have a feature that restricts memory pages from being both executable and writable at one time. The memory which is executable is mapped to be only read-execute, and vice versa.
In .Net 6.0, you can enable the W^X feature by setting the DOTNET_EnableWriterXorExecute value to 1. The reason why .Net 6.0 offers this feature as an option is because of the start regression. If you are working on an app without critical startup performance, this feature is imperative to offer better security.
Conclusion
.NET 6.0 release is just around the corner. Check the amazing features introduced in its preview releases and start preparing for this amazing change.
If you want support for .NET 6.0 development, our developers at Desuvit Technologies can help you. We have had a team of experts working on .NET for multiple years now. They understand these valuable changes and so we can help you create a cross-platform, robust app. Connect and Get a quote today!
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.
Enjoyed this article? Subscribe for more valuable and great content !
By subscribing, you agree with our privacy policy and our terms of service.