.NET 6 Preview 2 (Release notes + New features)
Tags: dotnet, csharp, programming, beginners
Published: 2021-06-18 13:05:00

## .NET 6 Preview 2 Announcement 📰

On **March 11** of this year _.NET 6 Preview 2_ was **officially announced**. This new version includes runtime performance improvements in initial versions of _.NET MAUI,_ new _APIs,_ compilers for _Apple Silicon_ and more.  
_Microsoft_ plans to release monthly previews through October. Releasing in **November** the **final version** of _.NET 6_, with all the new features, such as enhancements for all .NET applications, including **desktop, mobile, server,****cloud** and **_IoT._**

---

## Support 💻

This new version of .NET 6 can be downloaded **right now** for _Windows, Linux and MacOS._

As we have discussed before, .NET 6 will be officially released in November 2021 and will be **supported** for **3 years**. Microsoft promises that .NET 6 will be a big change from .NET 5.

The additions that Microsoft promises to bring are:

- Android
- iOS
- Mac and Mac Catalyst for x64 and M1 chips
-  Windows Arm64

---

## Performance 🚀

Microsoft claims that .NET 6 performance will be **much higher** than .NET 5\. That is very likely since we have seen how in the jumps of its previous versions the **performance** has been **increased** at the same time that the **memory consumption** has been **reduced**.

They also promise to **increase the performance** of tools and services to ensure that .NET developers are as productive as possible. Below we can see some of the first performance tests. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eu6pk5lqc9i9j1gnajjf.png)

---

## .NET has a lot of experience developing client applications. 👨‍💻

One of the most important parts of what comes to be .NET 6 is mobile development, which is now **offered separately** from Xamarin. Over time, _Xamarin_ has moved closer to the mainstream of .NET. At this time, with the development of Android, iOS and MacOs it will be integrated into the .NET SDK experience and the ._NET libraries_ will be used.

Microsoft tells us that over the years they have been working to incorporate _Mono_ into _.NET_, allowing developers to take full advantage of both runtimes without having to worry about compatibility or working with different .NET versions. Microsoft on .NET 5 moved **Blazor WebAssembly** and is currently using that same model for Xamarin.

Since all .NET applications will now run in the same libraries, Microsoft wants to **increase** the amount of code that is shared across desktop and mobile platforms. To do this they introduce us to **Xamarin.Forms**, Xamarin’s cross-platform user interface framework, which is evolving into the .NET cross-platform application user interface. This will allow you to easily write applications for Windows, MacOS, iOS and Android with the same code base. 

---

## .NET MAUI 🔝

They also tell us that .NET MAUI will be added as an **enhancement** to .NET 6.  
.NET MAUI is not just for client application developers. Thanks to all the .NET 6 enhancements, existing Blazor applications will run natively on MacOS and Windows via .NET MAUI.

Another major feature that Microsoft is focusing on is the **packaging issue**, as there are so many developers with different target platforms, alongside different ways of developing applications. At the end of the day that’s a lot of packages to distribute. They especially focus on applications with the _Blazor desktop_, as they want that experience to be as seamless as possible. 

Right now Microsoft is looking for strategies to **improve the release and version control** both locally and in the cloud, as well as on the desktop, so that developers can **package**, **distribute**, **launch** and **update** their applications on different architectures and desktop platforms. 

---

## Summary of what’s new in .NET6 🏅

*   You will be able to **create applications** for **MacOS, iOS and Android with the .NET libraries.**
*   It will allow to **create iOS, Android, Windows and MacOS applications** from the same code base **using .NET MAUI.**
*   The ability to **share more code and resources** between platforms (such as icons, images and more) will be implemented.
*   Ease of **running Blazor web applications** natively on **MacOS and Windows.**
*   You can **easily package and distribute** applications for all the target frameworks you include.


---

Microsoft ends (for now) telling us the news in .NET 6 telling us that they have made a **lot of progress** in development and that they will continue to **add more features** in each Preview of .NET 6.

We are going to dedicate the remainder of this article to dig a little deeper into the **new features** of **.NET 6 Preview 2.**

---

## Cross-platform .NET application user interface ✅

From Microsoft, they tell us they have **added .NET MAUIs** and unique project developer experiences for **Android iOS and Mac Catalyst**. They also tell us that they have updated their repository with samples of projects that can already be run with .NET 6 Preview 2.


---

## Mac Catalyst ✅

The function of adding the following *TargetFramework* configuration to any project will be implemented to be able to compile it on MacOS desktop, using **Mac Catalyst**.

``` csharp
<TargetFrameworks>net6.0-android;net6.0-ios</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">$(TargetFrameworks);net6.0-maccatalyst</TargetFrameworks>
```

Microsoft tells us that they have enabled a **unique experience for .NET MAUI** applications. Now what you get is a very clean solution that can be **run** on **Android, iOS, and MacOS.** They also tell us that they will add **Windows to .NET MAUI** in a future Preview.

---

## Shared application icons, images, and fonts ✅

Icons, images, and fonts can be placed in one location in your code, and the _.NET MAUI_ will allow you to work natively on all platforms it targets. These will just track _SharedImage_ or _SharedFont_ in your _.csproj_ file.

``` csharp
<ItemGroup>
    <SharedImage Include="appicon.svg" ForegroundFile="appiconfg.svg" IsAppIcon="true" />
    <SharedFont Include="Resources\Fonts\ionicons.ttf" />
  </ItemGroup>
```

Both accept **wildcards** to **include all files** within one location.

``` csharp
<ItemGroup>
    <SharedImage Include="appicon.svg" ForegroundFile="appiconfg.svg" IsAppIcon="true" />
    <SharedFont Include="Resources\Fonts\ionicons.ttf" />
  </ItemGroup>
```

---

## Launch applications with Host Builder with MauiApp ✅

They currently have extensions for configuring fonts, services, and compatibility renderers for migrate Xamarin.Forms projects. IWindow **was added** for multi-window support **in a future release**. They also aim to integrate library authors and control providers with the .NET MAUI.

``` csharp
public class Application : MauiApp
{
    public override IAppHostBuilder CreateBuilder() => 
        base.CreateBuilder()
            .RegisterCompatibilityRenderers()
            .ConfigureServices((ctx, services) =>
            {
                services.AddTransient<MainPage>();
                services.AddTransient<IWindow, MainWindow>();
            })
            .ConfigureFonts((hostingContext, fonts) =>
            {
                fonts.AddFont("ionicons.ttf", "IonIcons");
            });

    public override IWindow CreateWindow(IActivationState state)
    {
        Microsoft.Maui.Controls.Compatibility.Forms.Init(state);
        return Services.GetService<IWindow>();
    }
}
```

---

## Control drivers ✅

Lastly, the first controls and properties have been introduced that implement a new controller approach. These include partial label and input, button, and slider and switch implementations. The sample application is _HelloMaui_, it runs from a single project to **MacOS, iOS and Android** displaying the current set of ported controls.

**Mac OS**:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jupl5nhz410rvrb0f2vp.png)

**iOS**:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j0mxhbfwgrqcet2sbb2w.png)

**Android**:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mi0l5wokamb2mo0xkt38.png)