How .Net MAUI Works

What is .NET MAUI?

.NET MAUI stands for .NET Multi-Platform App UI, which is a cross-platform framework for creating native mobile as well as desktop apps with the C# and XAML. The purpose of .NET MAUI is to create applications that can run on various platforms, i.e., Windows, macOS, iOS, Android, etc., with a shared codebase.
.NET MAUI is open source, and it is evolved form of Xamarin.Forms, extended from mobile to desktop scenarios with UI controls rebuilt from the ground up for extensibility and performance.

The next question which comes to mind is, “How actually .NET MAUI works?”. Let’s understand with the below image.

.NET MAUI High Level Structure

As you can see in the above image, Application code written using .NET MAUI provides access to the platform-specific frameworks i.e., .NET Android, .NET iOS, .NET macOS, Windows UI 3 (WinUI 3) libraries. All these frameworks have access to a common .Net BCL (Base Class Library). BCL further depends on the .NET Runtime to provide the execution environment for the Application Code. For Windows, .NET CoreCLR provides the execution environment, whereas for Android, iOS, and macOS, Mono, which is an implementation for the .NET Runtime, provides the execution environment.

How to Get Started?

To start developing .NET MAUI apps on Windows, you need to install Visual Studio 2022  17.3 or greater. I am sharing the important steps below, which you can refer to in case you are using Windows OS (To build, sign, and deploy .NET MAUI apps for iOS, you need a Mac with the latest version of Xcode, An Apple ID, and a paid Apple Developer Program enrollment to submit the apps on the Apple Store).

Download Visual Studio 2022 from the Microsoft official website and run the installer.

Make sure to select .NET Multi-platform App UI development option checked in the workloads tab. Click on Install and wait till the installation is completed successfully.

Once Visual Studio 2022 is installed, click on the “Create a new project” button, as shown below.

Select the .NET MAUI App and click on Next.

Give a name to the project and click on Next.

Select the Framework as per your need. For demonstration, I am selecting .Net 6.0 framework having Long Term Support.

You will see the below Project structure created for .NET MAUI Application. We will understand the structure later in the upcoming article.

Let’s run the application on the Android Emulator. Before running the app, we need to set up our emulator. Click on the Android Emulators as shown in the below image.

Accept the Android SDK - License Agreement

Create a Default Android emulator, which may take a few minutes. Click on Create button to continue.

It will take time as it will download the image and configure it for your testing. Once the emulator is ready, you will see a start button that can be used for Running the emulator. Click on the Start button. 

Build and run the application on the emulator that we just configured.

As you can see, our application is deployed on the emulator for development/testing purpose. .NET MAUI supports the hot reload, which enables modification of the code even when the app is running.

In the above steps, we have seen the steps to run the code on an Android device but what about Windows? Let’s follow the below steps to run the code on a Windows machine.
Switch the launch of application from the Android to Windows. 

You will see a dialog box prompting you to enable the Developer mode setting in Windows. You must have to enable it in Windows to proceed. You can find that Developer Mode in the Settings app, under Privacy & Security > For developers in Windows 11. If you are using Windows 10 then need to go to the Settings app, under Update & Security > For developers.

Once it is enabled, re-run the application, and you will see your first Hello World app is running on the Windows machine.

References:

https://learn.microsoft.com/en-us/dotnet/maui/


Similar Articles