Get Started with .NET MAUI
Welcome to the world of .NET Multi-platform App UI (.NET MAUI)! This guide will help you set up your development environment and build your first cross-platform application.
What is .NET MAUI?
.NET MAUI is an open-source, cross-platform framework for creating native mobile and desktop applications with C# and XAML. It's the evolution of Xamarin.Forms, offering a modern, unified development experience for building apps that run on Windows, macOS, Android, and iOS from a single C# codebase.
Prerequisites
Before you begin, ensure you have the following installed:
- .NET SDK (version 6 or later recommended)
- Visual Studio 2022 (with the .NET MAUI workload installed) or Visual Studio Code with the C# Dev Kit and .NET MAUI extensions.
For detailed installation instructions, please refer to the official setup guide.
Creating Your First .NET MAUI App
Let's create a simple "Hello, World!" application.
Using the .NET CLI
Open your terminal or command prompt and run the following commands:
dotnet new maui -n MyMauiApp
Navigate into your new project directory:
cd MyMauiApp
And run your app:
dotnet build -t:Run -f net6.0-android
dotnet build -t:Run -f net6.0-ios
dotnet build -t:Run -f net6.0-maccatalyst
dotnet build -t:Run -f net6.0-windows
Note: The exact command to run may vary slightly depending on your target platform and SDK version.
Using Visual Studio
- Open Visual Studio 2022.
- Select "Create a new project".
- Search for ".NET MAUI App" and select the template.
- Click "Next".
- Enter your project name (e.g., "MyMauiApp") and location, then click "Create".
- Once the project is created, select your desired target platform from the toolbar dropdown (e.g., Windows Machine, Android Emulator) and click the Run button.
Understanding the Project Structure
Your .NET MAUI project has a well-defined structure:
- Platforms: Contains platform-specific project configurations (Android, iOS, Windows, macOS).
- Resources: Holds shared assets like images, fonts, and styles.
- App.xaml / App.xaml.cs: The entry point of your application.
- MainPage.xaml / MainPage.xaml.cs: The default landing page for your app.
Next Steps
Now that you have your first app running, you can explore further:
Learn XAML
Discover how to build user interfaces with XAML, the declarative UI markup language for .NET MAUI.
Learn XAMLExplore Controls
Dive into the rich set of built-in UI controls available in .NET MAUI.
View ControlsData Binding
Understand how to bind data to your UI elements for dynamic updates.
Data Binding Guide