Categories
.NET .NET 8 .NET 9 .NET MAUI Android Blazor C# Code Desktop Developer General Hybrid iOS macOS Mobile Preview Templates Visual Studio Web What's New Windows WinUI 3 Xamarin Xamarin.Forms

What’s New in .NET MAUI 9 Preview 2

Yesterday, the second preview release of the .NET MAUI 9 was hot off the press. Here is the changelog.

To install the preview version, please refer to this article: .NET MAUI on .NET 9.

The distinguishing characteristic of .NET MAUI, with its initial design objective, is its single-project architecture.

With the Single Project design, it is possible to target all supported platforms from one project, presenting a significant advantage across numerous scenarios. Paves the way for far more code sharing.

Quite akin to Xamarin.Forms, it is entirely feasible to integrate the multi-project architecture in .NET MAUI. This capability holds significant value for projects transitioning from Xamarin.Forms to .NET MAUI.

This preview release introduces a multi-project template for .NET MAUI.

dotnet new maui-multiproject

This approach entails the creation of an individual project for each platform, accompanied by a .NET MAUI class library housing the shared code.

The underlying program architecture remains the same. For more details, refer to this article.

Multi-Project Changes:

The MAUI pipeline has undergone a modification to further enhance its abstraction. The file MauiProgram.cs has been relocated to the platform project, with only the shared startup logic retained in the class library as an App builder extension method named UseSharedMauiApp(). This method is then invoked in the platform project.

Also, the definition of the SingleProject project property is not necessary.

Since the platform code is hosted in individual projects, typical dotnet build and dotnet run commands can be utilized in the usual manner, without the need to pass the target framework moniker (TFM) as a parameter.

It is also feasible to limit the project template to generating solely the necessary platform projects by utilizing a CLI parameter designated for each platform. For more details:

dotnet new maui-multiproject -h

The template is also accessible within the Visual Studio IDE with the platform selection as UI options.

.NET MAUI - Multi-Project App with the option to Select Platforms
.NET MAUI – Multi-Project App with the option to Select Platforms

.NET 8 Update:

The changelog denotes its inclusion in the .NET MAUI 8 Service Release 3 (SR3) version too. This update, labeled as 8.0.10, has been released as a NuGet package update.

To install the latest templates pack, execute the following command. Before that, ensure that the CLI is in the .NET 8 context by executing the command dotnet --version.

dotnet new install Microsoft.Maui.Templates.net8 --force

Note: A refreshed version of this template package is now available. Update now.

dotnet new update

All-in-One Templates:

It is noteworthy that the All-in-One template already includes the capability to select a specific platform(s) using the --target-platform / -tp parameter. Furthermore, it can accept multiple values.

dotnet new mauiapp -o MyApp -tp Android iOS

And within Visual Studio as a multi-select dropdown.

.NET MAUI - All-in-One Template - Support for Target Platform Selection
.NET MAUI – All-in-One Template – Support for Target Platform Selection

The All-in-One template pack too has been updated to support the latest release. Kindly update to the most recent version.

If you would like to recognize the work, kindly consider sponsoring on the GitHub Sponsor page or Buy Me a Coffee page. Thanks in advance.

Happy coding. Stay connected as we continue to learn and share the experiences from this exciting journey of being a .NET developer.

2 replies on “What’s New in .NET MAUI 9 Preview 2”

Comments are closed.