Getting Started with .NET MAUI

Welcome to your first .NET MAUI application! This guide will walk you through the essential steps to create, build, and run a simple .NET MAUI app.

Prerequisites

Before you begin, ensure you have the following installed:

Important: If you haven't installed the .NET MAUI workload, please refer to the Installation Guide.

Creating Your First .NET MAUI App

You can create a new .NET MAUI project using either Visual Studio or the .NET CLI.

Using Visual Studio

  1. Open Visual Studio.
  2. Select "Create a new project".
  3. Search for ".NET MAUI App" and select the template.
  4. Click "Next".
  5. Enter a project name (e.g., "MyFirstMauiApp") and a location.
  6. Click "Create".

Using the .NET CLI

Open your terminal or command prompt, navigate to the directory where you want to create your project, and run the following command:

dotnet new maui -n MyFirstMauiApp

This command creates a new directory named "MyFirstMauiApp" containing your project files.

Understanding the Project Structure

Once your project is created, you'll see a standard .NET project structure. Key folders include:

Running Your App

To see your app in action, you need to build and deploy it to a simulator or a physical device.

On Windows (Visual Studio)

  1. Select a target framework (e.g., "Windows Machine") from the dropdown in the Visual Studio toolbar.
  2. Click the "Start" button (or press F5).

On macOS (Visual Studio for Mac)

  1. Select a target platform (e.g., "Mac Catalyst" or an iOS simulator) from the dropdown.
  2. Click the "Run" button (or press Cmd+R).

Using the .NET CLI

Navigate to your project directory in the terminal and use the following commands:

cd MyFirstMauiApp
dotnet build -t:Run -f net7.0-android

Replace net7.0-android with your desired target framework (e.g., net7.0-ios, net7.0-maccatalyst, net7.0-windows).

Screenshot of a simple .NET MAUI 'Hello, World!' app running on a device.
Your first .NET MAUI application.

Your First Code Modification

Let's make a small change to the main page.

  1. Open MainPage.xaml in your editor.
  2. Locate the <Label> element.
  3. Change the Text attribute from "Hello, World!" to "Hello, MAUI!".
<Label Text="Hello, MAUI!" ... />

Save the file and rebuild your application. You should now see "Hello, MAUI!" displayed on the screen.

Next Steps

Congratulations! You've successfully created and run your first .NET MAUI application. Continue exploring by learning about: