This guide will walk you through creating, building, and deploying a .NET MAUI app for Android/iOS (even if you're a complete beginner).
πΉ Step 1: Install Prerequisites
Before coding, ensure you have the right tools:
1. Install Visual Studio 2022 (Windows/Mac)
Select .NET Multi-platform App UI development workload:
Windows:
Visual Studio 2022 Setup for .NET MAUI (Windows)
Step 1: Install the .NET MAUI Workload
Open Visual Studio Installer (search for it in the Start menu).
Click Modify on your installed Visual Studio 2022 version.
Under Workloads, select:
.NET Multi-platform App UI development
(This includes Android, iOS, and Windows support.)
https://learn.microsoft.com/en-us/dotnet/maui/media/installation/vs-workloads.png?raw=true
(Source: Microsoft Docs)Click Modify to install.
Mac: Install .NET MAUI via Visual Studio for Mac.
2. Install .NET 8.0+ SDK
Download from dotnet.microsoft.com
3. Enable Developer Mode (Windows only)
Go to Settings → Update & Security → For Developers → Enable Developer Mode.
4. (Optional) Android Emulator / iOS Simulator
Android: Install via Tools → Android → Android Device Manager.
iOS (Mac only): Requires Xcode (from App Store).
πΉ Step 2: Create a New MAUI Project
Open Visual Studio → Create a new project.
Search for ".NET MAUI App" → Select C# → Click Next.
Name your project (e.g.,
MyFirstMauiApp
) → Choose a location → Click Create.
πΉ Step 3: Understand the Project Structure
MAUI projects have a shared codebase for all platforms:
MyFirstMauiApp/ ├── Platforms/ # Platform-specific code (Android, iOS, etc.) ├── Resources/ # Images, fonts, and assets ├── App.xaml # Global app styling & resources ├── App.xaml.cs # App entry point └── MainPage.xaml # Default UI page
πΉ Step 4: Build Your First Screen
1. Edit MainPage.xaml
Replace the default code with a simple UI:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MyFirstMauiApp.MainPage"> <VerticalStackLayout Spacing="20" Padding="30"> <!-- Header --> <Label Text="Welcome to MAUI!" FontSize="32" HorizontalOptions="Center" /> <!-- Image --> <Image Source="dotnet_bot.png" WidthRequest="200" HeightRequest="200" HorizontalOptions="Center" /> <!-- Button --> <Button Text="Click Me!" Clicked="OnButtonClicked" HorizontalOptions="Center" /> <!-- Counter Label --> <Label x:Name="CounterLabel" Text="Count: 0" FontSize="18" HorizontalOptions="Center" /> </VerticalStackLayout> </ContentPage>
2. Edit MainPage.xaml.cs
(Code-Behind)
Add button click logic:
public partial class MainPage : ContentPage { int count = 0; public MainPage() { InitializeComponent(); } private void OnButtonClicked(object sender, EventArgs e) { count++; CounterLabel.Text = $"Count: {count}"; if (count == 1) CounterLabel.Text += " (Click again!)"; } }
πΉ Step 5: Add an Image
Download an image (e.g.,
dotnet_bot.png
).Place it in
Resources/Images/
.Set its Build Action to MauiImage (right-click → Properties).
πΉ Step 6: Run the App
On Windows (Android)
Select Android Emulator from the dropdown.
Click Start Debugging (F5).
On Mac (iOS)
Select iOS Simulator.
Click Start Debugging (F5).
✅ You should see your app running!
πΉ Step 7: Deploy to a Physical Device
Android
Enable USB Debugging on your phone (Settings → Developer Options).
Connect via USB → Select your device in Visual Studio → Run.
iOS (Mac only)
Connect iPhone via USB.
Select your device → Run.
πΉ Step 8: Publish to App Stores
Android (Google Play Store)
Build in Release Mode:
Right-click project → Publish → Create Android App Bundle (.aab).
Upload to Google Play Console.
iOS (Apple App Store)
Archive in Release Mode:
Right-click project → Archive for Publishing.
Upload via App Store Connect.
πΉ Next Steps
Explore MAUI Documentation
Try adding:
Navigation (
Shell
orNavigationPage
)Data Binding (
MVVM
pattern)API calls (
HttpClient
)
π Congratulations! You Built Your First MAUI App!
Now you can customize it further and publish it to app stores.
No comments:
Post a Comment