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:
Already have Visual Studio?
If you already have Visual Studio 2022 Preview, you can update your installation to add .NET MAUI support.
Select the Windows key, type Visual Studio Installer, and press Enter.
If prompted, allow the installer to update itself.
If an update for Visual Studio 2022 Preview is available, an Update button will be shown. Select it to update before modifying the installation.
Find your Visual Studio 2022 Preview installation and select Modify.
Select .NET Multi-Platform App UI development.
Select the Modify button.
Create your app
Create a new .NET MAUI app:
Open Visual Studio 2022 Preview.
Select the Create a new project button.
Select MAUI from the Project type drop-down.
Select the .NET MAUI App (Preview) template and select the Next button.
Enter MyFirstMauiApp as the project name and select the Create button.
Android SDK Install
Specific versions of the Android SDK are required to build projects. If your machine is missing the required SDK, you'll see the following prompt while the new project is loading. Click Accept to have the automatic installation begin.
Restore NuGet packages
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.
Configure device
This tutorial will focus on deploying a .NET MAUI application to your local Windows machine or to an Android device or emulator. You can decide to deploy to one or more of the platforms based on your development environment.
Set up Windows for development
To develop Windows applications, you will need to enable developer mode to sideload applications on Windows 11 or Windows 10.
Enable developer mode
On Windows, go to the Settings application.
Search for Developer settings, which is located under For developers in Privacy & security on Windows 11 and Update & Security on Windows 10.
Turn on the toggle under Developer Mode.
The Use developer features dialog is displayed. Select Yes to confirm that you want to enable the developer mode.
Set up Android emulator
If you don't have an Android device to deploy to, you can set up an Android emulator. If you've already done this, you can skip this step.
If this if your first time building a .NET MAUI application, you'll see "Android Emulator" in the debug menu. Click it to start the creation process.
This brings up a User Account Control prompt to be accepted and then the emulator 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 Start. Click it.
You may receive prompt to enable Windows Hypervisor Platform. Follow the documentation to enable this feature for optimal performance.
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.
Set up Android device
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
Go to the Settings screen.
Find Build number by using search at the top of the settings screen, or locate it in About phone.
Tap Build number 7-10 times until "You are now a developer!" pops up.
Click Create.
Check USB debugging status
Go to the Settings screen.
Find USB debugging by using search at the top of the settings screen, or locate it in Developer options.
Enable USB debugging if it isn't enabled already.
Trust device
Plug your device into your computer.
You'll be prompted to Allow USB debugging.
Check Always allow from this computer.
Click Allow.
Your device is now configured and will show up in Visual Studio as a deployment target.
From the debug drop down menu, select net6.0-windows under Framework. Once selected, you should see Windows Machine as the debug target.
From the menu, select Debug > Start Debugging.
Run on Android
From the debug drop down menu, select net6.0-android under Framework.
From the menu, select Debug > Start Debugging. If this option is disabled, ensure an emulator is selected. If you don't have an emulator, select Android Emulator and you'll be guided through creating a new emulator.
Your application will build then deploy to the Android device/emulator and run.
Congratulations, you've built and run your first .NET MAUI app!
Edit your code
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.
In the Solution Explorer, double-click the MainPage.xaml file under the MyFirstMauiApp project.
Currently, the Text of the first Label is set to say Hello, World! as shown in the following code:
Save your changes by selecting File > Save or select CTRL+S and the UI will update.
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.
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: