dotnet maui cross platform development

In this new post I show you how to install MAUI with Visual Studio 2022 (Preview) after the official release of Visual Studio 2022.

This is a substantial update to my previous post Install MAUI with Visual Studio 2022.

Now, MAUI replaces Xamarin and is a name for a new upgrade solution as a Multi-platform App UI framework for building native cross-platform apps with .NET for Android, iOS, macOS, and Windows. I am going to show how to create, build and debug the First MAUI application using Visual Studio 2022 (Preview).

Install Visual Studio 2022 Preview

So, I suppose all of us has already installed Visual Studio 2022 but unfortunately MAUI is not coming with it. First, we have to install a preview of Visual Studio 2022 and you can download it from Visual Studio 17.1 Preview 1.

Then, launch the installation and in the list of workloads you have to select Mobile development with .NET.

Visual Studio 2022 Preview workloads - Install MAUI with Visual Studio 2022 (Preview)
Visual Studio 2022 Preview workloads

Relax, the installation for only this function requires at least half an hour.

Visual Studio Installer in progress - Install MAUI with Visual Studio 2022 (Preview)
Visual Studio Installer in progress

Create a new project

So, now in Visual Studio 2022 you should find the .NET MAUI App. Now, we want to create the first project. Click on the type of project you like. I start with the .NET MAUI App.

Create a new project with MAUI - Install MAUI with Visual Studio 2022 (Preview)
Create a new project with MAUI

Now, choose Project Name, Location, Solution Name as usual.

Configure your new MAUI project
Configure your new MAUI project

MAUI Project Solutions Structure

So, after clicking on Create, MAUI solutions default template is loaded with all the related MAUI NuGet packages. There is a single project with different platform folders and resources.

Finally, we have only one project and only one folder for all the platforms! When I wrote Install MAUI with Visual Studio 2022, the solution had 2 projects: one for Windows and another one for the other platforms. Good progress!

.NET Generic Host

So, the Visual Studio template create a .NET Generic Host, HostBuilder. The .NET Generic Host can be used with other types of .NET applications, such as Console apps.

Now, MAUI Program class enables apps to be initialized from a single location, and provides the ability to configure fonts, services, and third-party libraries.

So, iOS, Android, windows, and all the platform entry point calls a CreateMauiApp method of the static MauiProgram class that creates and returns a MauiApp, while lunching the application.

MauiProgram.cs
MauiProgram.cs

Resources

Now, the resources are a good improvement in MAUI. The AppIcon, image and font folder will be available under the MAUI project. And it is just a single SVG! Looks like MAUI will just automatically take care of generating all the different icon sizes for different devices.

Run iOS App

First, as usual, building MAUI iOS applications requires access to Apple’s build tools, which only run on a Mac. Because of this, Visual Studio 2022 must connect to a network-accessible Mac to build iOS applications.

You must install the Xcode 13.1++ version on the Mac machine before connecting Visual Studio 2022 to the Windows machine.

MAUI app runs in iPhone 11 Pro with Visual Studio 2022
MAUI app runs in iPhone 11 Pro with Visual Studio 2022

Run Android

Now, running an Android app in a device or emulator with Visual Studio is quite straightforward. What if you don’t have an Android device? I’m amazed to say that from now on we can use Windows Subsystem for Android to debug applications without any emulator! I’m very exciting to show you how in my post Android debugging with Windows Subsystem.

Here the Windows Subsystem for Android in Visual Studio 2022.

So, the app is like that. Amazing!

MAUI application for Android running on Windows Subsystem for Android
MAUI application for Android running on Windows Subsystem for Android

Run Windows

And now, the MAUI app running on Windows 11!

MAUI app for Windows
MAUI app for Windows

By Enrico

My greatest passion is technology. I am interested in multiple fields and I have a lot of experience in software design and development. I started professional development when I was 6 years. Today I am a strong full-stack .NET developer (C#, Xamarin, Azure)

This site uses Akismet to reduce spam. Learn how your comment data is processed.