- Visual Studio 2022 17.12 or greater, with the .NET Multi-platform App UI workload installed. For more information, see Installation.
In this tutorial, you'll create your first .NET MAUI app in Visual Studio 2022 and run it on an Android emulator:
Developing .NET MAUI apps for iOS on Windows requires a Mac build host. If you don't specifically need to target iOS and don't have a Mac, consider getting started with Android or Windows instead.
In this tutorial, you'll create your first .NET MAUI app in Visual Studio and run it on an iOS simulator:
In this tutorial, you'll create your first .NET MAUI app in Visual Studio 2022 and run it on Windows:
Launch Visual Studio 2022. In the start window, click Create a new project to create a new project:
In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
In the Configure your new project window, name your project, choose a suitable location for it, and click the Next button:
In the Additional information window, choose the version of .NET that you'd like to target and click the Create button:
Wait for the project to be created and its dependencies to be restored:
In the Visual Studio toolbar, use the Debug Target drop-down to select Android Emulators and then the Android Emulator entry:
In the Visual Studio toolbar, press the Android Emulator button:
Visual Studio will start the process of installing the default Android SDK and Android Emulator.
In the Android SDK - License Agreement window, press the Accept button:
In the User Account Control dialog, press the Yes button:
Wait for Visual Studio to download the default Android SDK and Android Emulator.
In the User Account Control dialog, press the Yes button:
In the Android SDK Platform is missing dialog, press the Install button:
In the Android SDK - License Agreement window, press the Accept button:
Wait for Visual Studio to install the Android SDK components.
In the New Device window, press the Create button:
Wait for Visual Studio to download, unzip, and create an Android emulator.
Close the Android Device Manager window:
In the Visual Studio toolbar, press the Pixel 7 - API 35 (Android 15.0 - API 35) button:
In the Android SDK - License Agreement window, press the Accept button:
In the User Account Control dialog, press the Yes button:
Wait for Visual Studio to install to download the Android SDK.
In the Visual Studio toolbar, press the Pixel 7 - API 35 (Android 15.0 - API 35) button to build and run the app:
Visual Studio will start the Android emulator, build the app, and deploy the app to the emulator.
In the running app in the Android emulator, press the Click me button several times and observe that the count of the number of button clicks is incremented.
If your app fails to compile, review Troubleshooting known issues, which may have a solution to your problem. If the problem is related to the Android emulator, see Android emulator troubleshooting.
In the Visual Studio toolbar, press the Windows Machine button to build and run the app:
In the running app, press the Click me button several times and observe that the count of the number of button clicks is incremented:
If your app fails to compile, review Troubleshooting known issues, which may have a solution to your problem.
In Visual Studio, pair the IDE to a Mac Build host. For more information, see Pair to Mac for iOS development.
In the Visual Studio toolbar, use the Debug Target drop-down to select iOS Simulators and then a specific iOS simulator:
In the Visual Studio toolbar, press the Start button for your chosen iOS simulator to build and run your app:
Visual Studio will build the app, start the remote iOS Simulator for Windows, and deploy the app to the remote simulator. For more information about the remote iOS Simulator for Windows, see Remote iOS Simulator for Windows.
In the running app, press the Click me button several times and observe that the count of the number of button clicks is incremented.
If your app fails to compile, review Troubleshooting known issues, which may have a solution to your problem.
.NET MAUI apps that target Mac Catalyst can only be launched and debugged using Visual Studio Code.
- Visual Studio Code, with the .NET MAUI extension installed. For more information, see Installation.
To create a new .NET MAUI app:
- Launch Visual Studio Code. In the Explorer, click Create .NET Project in the Explorer. Alternatively, select CTRL/CMD+SHIFT+P .NET: New Project....
- Select .NET MAUI App or .NET MAUI Blazor App.
- Select an empty folder. If the file explorer opens again, your folder is not empty.
- Name the project.
- Ensure the project loads successfully in the Solution Explorer, and then open a C# or XAML file.
Note
You can also open an existing .NET MAUI project in Visual Studio Code via the File > Open... menu.
You should now see your app in C# Dev Kit's Solution Explorer in Visual Studio Code. Since the .NET MAUI extension depends on C# Dev Kit, you can use all of its features alongside the .NET MAUI extension.
Choose your target device
To choose your target device, click on the curly brackets symbol { } in the bottom right corner of Visual Studio Code. You can use this symbol to change your startup project, change your debug target to anything valid on your development machine, and pin either setting to the Visual Studio Code status bar:
You can also set the startup project and debug target in the command palette, using CTRL/CMD+SHIFT+P and searching for ".NET MAUI".
You can deploy to your local development machine (Windows desktop or macOS with Xcode) without any additional steps.
If you want to use Android emulators, follow these steps to install and create an emulator:
Navigate in your terminal to <YOUR_ANDROID_SDK_DIRECTORY>/cmdline-tools/11.0/bin/
.
Use sdkmanager
to install the emulator.
On Windows, run the following commands in the terminal:
sdkmanager --install emulator
sdkmanager --install "system-images;android-33;google_apis;x86_64"
On macOS, run the following commands in the terminal:
./sdkmanager --install emulator
./sdkmanager --install "system-images;android-33;google_apis;x86_64"
Note
The quotes around the sdkmanager
command-line arguments are important.
Then, you can create a new emulator on the command line with Android's avdmanager.
On Windows, run the following commands in the terminal:
avdmanager create avd -n MyAndroidVirtualDevice-API33 -k "system-images;android-33;google_apis;x86_64"
On macOS, run the following commands in the terminal:
./avdmanager create avd -n MyAndroidVirtualDevice-API33 -k "system-images;android-33;google_apis;x86_64"
Note
The quotes around the avdmanager
command-line arguments are important.
You can also debug on physical Android devices.
iOS simulators are built into Xcode. To download the simulators, either ensure that the option is selected to install them when Xcode first launches, or navigate to Xcode > Settings > Platforms and choose a simulator runtime to install.
To debug with an iOS device, follow these steps before attempting to debug:
- Specify your Apple ID in Xcode > Settings > Account.
- Register the device with your team if you belong to the Apple Developer Program.
- Enable Developer Mode on your device, as described in Enabling Developer Mode on a device. The first time you run your app you may receive a pop-up on the device - ensure you select Allow.
To debug your app, navigate to Visual Studio Code's Run and Debug menu and select the Run and Debug button. Alternatively, you can use F5 to start a debug session. If Visual Studio Code prompts you to select a debugger, ensure you select C#.
Note
In preview versions of the extension, the debugger was listed as .NET MAUI. In the stable release, this configuration was replaced with C#.
The debugger will automatically choose the debug target and startup project you set in the curly brackets { } menu. If you haven't selected anything, you'll be prompted to choose a debug target.
Once your app starts debugging, you can use the built-in Visual Studio Code debugging tools to set breakpoints, step throughout your code, and more.
If you face any issues with the extension, you can follow the troubleshooting steps, see the known issues, or provide feedback.