Aloha, .NET MAUI

By | August 5, 2021

UPDATE: This post has been updated to the latest version of the VS2022 preview.

If you are a Xamarin developer, it’s pretty likely you have already heard of .NET MAUI. If not, I’d say the best way to describe it is that it is a successor to Xamarin Forms. I say a successor instead of a rebranding because it has been rebuilt from the ground up, and built on top of .NET 6. Up until now, Xamarin has been running on top of the Mono implementation of the .NET framework. Going forward, .NET MAUI (MAUI stands for Multi-platform App UI) is the framework you will use to build cross platform apps with .NET. MAUI will be released with Visual Studio 2022, currently targeted for a November 2021 release.

Some highlights of MAUI:

  • New framework for controls (replaces Renderers) with improved performance and easier customization
  • Single project targeting all platforms
  • Built on .NET 6
  • Improved tooling
  • Easy migration from Xamarin Forms
  • New MVU pattern implementations to create UI using .NET code (an alternative option to XAML)
  • Blazor integration (more on this in future posts, very exciting)

I’ve been following the progress of MAUI for over a year now, and it has finally progressed to the point that you don’t have to jump through a ton of hoops to get it going, and most features are implemented in the latest release. This is why I feel it’s a good time to introduce you to MAUI. I will likely be posting almost exclusively about MAUI throughout the rest of this year, and diving into a lot of the new stuff.

Getting Started With .NET MAUI

I’ll try to keep this part up to date as we get new preview and release candidate builds of .NET MAUI. At the time of this writing, the current release is .NET MAUI Preview 8, which is tied to Visual Studio 2022 Preview 4.

First, install Visual Studio 2022 Preview 4. You can install this side by side with any other version of Visual Studio.

When you are prompted to install Workloads, choose the Mobile Development with .NET workload, and then choose the optional .NET MAUI (Preview) package.

dotnet new maui -n AlohaMaui

Now you can load the solution just like any other in Visual Studio 2022, and you’ll see something like this.

Right away if you’re used to Xamarin Forms you will see some big differences. First of all, there are not separate iOS and Android projects. Things have been inverted and the per platform boiler plate and other platform specific files are now in folders in the MAUI project. Also note the Resources folder. There is now a single place to put fonts, images, and other files that are to be shared across platforms, and at build/packaging time these are put in the correct places for each of the platforms. There is support for the SVG image format directly out of the box which is nice.

There is also a WinUI project, which allows the MAUI app to run on Windows desktop.

In order to run MAUI apps on Windows Desktop, you will need to install the Visual Studio extension Single-project MSIX Packaging Tools for VS 2022. Without this, when you go to run the desktop version of the app, it will complain there is no valid target.

To run the desktop version of the app, set the WinUI project as the startup project. Taking a quick look at the WinUI project, it also has a Resources folder which has an exact copy of all of the files in the main project. I have heard word that this situation is temporary, and that the WinUI project will go away at some point.

Here is the app running on Windows desktop:

Now .NET MAUI is still in preview, and we see a couple of issues here with clipping of text, if you make the window slightly wider it fixes itself:

For Android and iOS, set the main project as the startup project and then pick your desired target from the dropdown:

Note that you need a Mac that is network accessible to develop for iOS and MacOS.

Aloha and more to come soon. For more information about this release, see David Ortinau’s blog post.

Leave a Reply

Your email address will not be published. Required fields are marked *