Set up your development environment and build your first .NET Multi-platform App UI (.NET MAUI) app.
Check the system requirements for Visual Studio 2022.
Check the system requirements for Visual Studio for Mac 2022 and the minimum requirements for the latest version of Xcode.
10 minutes + download/installation time
A mobile and desktop app that runs on Windows and Android that displays a Hello, World!
message.
A mobile and desktop app that runs on Mac and Android that displays a Hello, World!
message.
Download and install Visual Studio 2022.
During installation, the .NET Multi-platform App UI development workload should be selected. Using the link above should preselect all the prerequisites correctly, as shown on the following image:
If you already have Visual Studio 2022, you can update your installation to add .NET MAUI support:
Download and install Visual Studio 2022 for Mac.
Download Visual Studio 2022 for Mac
During installation, ensure the following workloads are selected:
The last two workloads (Android and iOS) should be automatically selected once you select .NET MAUI.
This tutorial is optimized for the latest version of Visual Studio for Mac. If you already have Visual Studio 2022 for Mac, you can check for updates:
To build .NET MAUI apps, you'll also need:
An Apple ID
If you don't already have an Apple ID, you can create a new one at https://appleid.apple.com. An Apple ID is required for installing and signing into Xcode.
After installing Xcode, you must open Xcode, agree to terms of service, and install optional components, if prompted.
Create a new .NET MAUI app:
In the Create a new project window, type MAUI App in the search bar. Select the .NET MAUI App template, and then click the Next button.
In the Configure your new project window, enter MyFirstMauiApp as the project name and click the Next button.
In the Additional information window, select .NET 8.0 (Long Term Support) in the Framework drop-down if not already selected and click the Create button.
Visual Studio creates the new project. If you get a Windows Security Alert warning you about the firewall blocking some features, select the Allow access button.
NuGet is a package manager that will bring in the dependencies of your new app.
The package restore process will start automatically. Wait until the Restored or Ready message appears in the status bar at the bottom left of the screen.
In the Choose a template for your new project window, select Multiplatform > App, select the .NET MAUI App template, and click the Continue button.
In the Configure your new .NET MAUI App window, select .NET 7.0 in the Target framework dropdown if not already selected and click the Continue button:
Enter MyFirstMauiApp as the Project name and click the Create button.
This tutorial will focus on deploying a .NET MAUI application to your local Windows machine first. Later, you'll have the option to set up an Android device or emulator.
In the Visual Studio toolbar, you should see Windows Machine as the debug target by default. Press the Windows Machine button to build and run the app:
If you haven't enabled Developer Mode yet, Visual Studio will prompt you to enable it. In the Enable Developer Mode for Windows dialog, click the settings for developers link to open the Settings app:
Depending on your version of Windows, this setting may look a little different. Turn on the toggle either under or next to Developer Mode.
The Use developer features dialog is displayed. Select Yes to confirm that you want to enable the developer mode.
Close the Settings app, and then close the Enable Developer Mode for Windows dialog. The app should start running.
In the running app, select the Click me button a few times and observe that the count of the number of button clicks is incremented:
This tutorial will focus on deploying a .NET MAUI application to your local Mac machine first. Later, you'll have the option to set up an Android device or emulator.
In the Visual Studio toolbar, you should see My Mac as the debug target by default. Press the play icon (▶) to build and run the app:
In the running app, select the Click me button a few times and observe that the count of the number of button clicks is incremented:
Congratulations, you've built and run your first .NET MAUI app! Keep the app running and continue the tutorial.
When developing applications with .NET MAUI, XAML Hot Reload is available when you're debugging your application. This means that you can change the XAML user interface (UI) while the application is running and the UI will update automatically.
Go back to Visual Studio and leave the app running. In the Solution Explorer, double-click the MainPage.xaml
file under the MyFirstMauiApp
project. If you don't see the Solution Explorer pane, select View > Solution Explorer from the main menu (or press CTRL+ALT+L).
Go back to Visual Studio and leave the app running. In the Solution window, double-click the MainPage.xaml
file under the MyFirstMauiApp
project. If you don't see the Solution window, select View > Solution from the main menu.
Currently, the Text
of the first Label
is set to say Hello, World!
as shown in the following code:
<Label
Text="Hello, World!"
Style="{StaticResource Headline}"
SemanticProperties.HeadingLevel="Level1" />
Update the text to read Hello, .NET MAUI!
:
<Label
Text="Hello, .NET MAUI!"
Style="{StaticResource Headline}"
SemanticProperties.HeadingLevel="Level1" />
The app UI updates automatically as you make changes.
When developing applications with .NET MAUI, you can also use .NET Hot Reload to reload your C# code. Let's modify the logic in the application to increment the count by 10 instead of by 1 when you click the button.
Open MainPage.xaml.cs
(this file is nested under MainPage.xaml, or you can right-click and select View Code from the menu).
The OnCounterClicked
method on that file currently has the following code:
private void OnCounterClicked(object sender, EventArgs e)
{
count++;
if (count == 1)
CounterBtn.Text = $"Clicked {count} time";
else
CounterBtn.Text = $"Clicked {count} times";
SemanticScreenReader.Announce(CounterBtn.Text);
}
Update the count++;
to increment by 10 by changing it to count += 10;
.
private void OnCounterClicked(object sender, EventArgs e)
{
count += 10;
if (count == 1)
CounterBtn.Text = $"Clicked {count} time";
else
CounterBtn.Text = $"Clicked {count} times";
SemanticScreenReader.Announce(CounterBtn.Text);
}
To apply your code changes, save the file and select the Hot Reload button in Visual Studio or select ALT+F10.
Select the Click me button and see it increment by 10. Well done! You can close the running app now.
You can decide to deploy to one or more of the platforms based on your development environment. You just ran and deployed your app to Windows. Now, let's set up an Android device or emulator.
In your Windows Search Bar, type Windows features and select Turn Windows features on or off.
Make sure the Hypter-V box is checked and select Ok.
You'll need to reboot your machine at this time for the change to take effect.
Open Visual Studio and your MyFirstMauiApp solution. From the debug target drop-down menu, select net8.0-android under Framework.
Specific versions of the Android SDK are required to build projects. If you haven't accepted the Android SDK license, you'll see the following error message on the Error List window.
Double click the message to start the license acceptance process. Click Accept for each of the licenses present and the automatic installation will begin.
If you don't have an Android device to deploy to, you can follow these steps to set up an Android emulator. If you've already done this or want to use your own Android device, you can skip this step.
If this is your first time building a .NET MAUI application, you'll see Android Emulator selected in the debug target drop-down menu. Click it to start the creation process. If a license acceptence dialog shows up, select Accept.
This brings up the New Device window. Select the Create button to create an emulator with default settings. This will download the emulator images and finalize the creation of the emulator for use in Visual Studio. This step might take a while.
Don't worry if the API Level you see is different from the images. It may be 33 or higher.
Once the emulator has been created, you'll see a button that says Start. Click it.
You may receive prompt to enable Windows Hypervisor Platform. Follow the documentation to enable acceleration to improve performance (required to get the emulator up and running). Select Run Anyway.
The Android emulator will launch and will be fully finished when you see the ability to Stop in the Android Device Manager. This may take some time.
Once it's fully finished, you'll see it displayed in the Visual Studio debug menu.
Your Android emulator has now been created and is ready to use. Next time you run Visual Studio, the emulator will appear directly in the debug target window and will start when you select it. If you ran into any issues or have performance issues with the emulator, read through the full setup documentation.
You can decide to deploy to one or more of the platforms based on your development environment. You just ran and deployed your app to Mac. Now, let's set up an Android device or emulator.
If this if your first time building a .NET MAUI application, you'll need to create a new Android Emulator. You'll see Android Emulator in the debug menu. Press the play icon (▶) to start the creation process.
The options are automatically populated for a base emulator. If required, change any options and then select Create.
At this point, you may be prompted to agree to the license agreement for the Android emulator. Read through and select Accept to continue the process. This will download the emulator images and finalize the creation of the emulator for use in Visual Studio.
Once the emulator has been created, you'll see a button that says Play. Click it.
The Android emulator will launch. Wait for it to fully finish starting and you'll see it displayed in the Visual Studio debug menu. This may take some time if you aren't using hardware acceleration.
Your Android emulator has now been created and is ready to use. Next time you run Visual Studio, the emulator will appear directly in the debug target window and will start when you select it. If you ran into any issues or have performance issues with the emulator, read through the full setup documentation.
To develop with your Android device, USB debugging needs to be enabled. Follow these steps on the device to connect it to Visual Studio. If you don't have an Android device, you can skip this section.
Enable developer mode
Check USB debugging status
Trust device
Your device is now configured and will show up in Visual Studio as a deployment target.
Having issues? Check the documentation.
Your emulator or device should now be configured for deployment!
Make sure your device or emulator is selected as a debug target.
From the menu, select Debug > Start Debugging (or press F5). If this option is disabled, ensure an emulator or device is selected.
From the menu, select Debug > Start Debugging. If this option is disabled, ensure an emulator or device is selected.
Your application will build, deploy to the Android device/emulator selected, and run.
Congratulations, you've built and run your first .NET MAUI app!
Now that you've got the basics, continue learning how to build .NET MAUI apps with the self-guided learning path on Microsoft Learn.
Let James walk you through building a full .NET MAUI app from start to finish:
You might also be interested in...