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.
Relax, the installation for only this function requires at least half an hour.
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.
Now, choose Project Name, Location, Solution Name as usual.
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.
Now, the resources are a good improvement in MAUI. The
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.
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!
And now, the MAUI app running on Windows 11!