Saturday, September 11, 2021

How to create and run your first .NET Multi-platform App UI (.NET MAUI) app?

Prerequisites

  • The latest preview of Visual Studio 2022, with the required workloads. For more information, see Installation.
  • An environment that has been configured for .NET MAUI development. For more information, see Install latest .NET 6.
  • A configured Android emulator. For more information about creating an Android emulator, see Android emulator setup.

Get started with Visual Studio 2022 (Preview)

In this tutorial, you'll create your first .NET MAUI app in Visual Studio 2022, and run it on an Android emulator:

  1. Launch Visual Studio 2022, and in the start window click Create a new project to create a new project:

    New solution.

  2. In the Create a new project window, select MAUI in the Project type drop-down, select the .NET MAUI App template, and click the Next button:

    Choose a template.

  3. In the Configure your new project window, name your project, choose a suitable location for it, and click the Create button:

    Configure the project.

  4. Wait for the project to be created, and its dependencies to be restored:

    Restored dependencies.

  5. In the Visual Studio toolbar, select the drop-down next to the Start button (the triangular button that resembles a Play button), select Android Emulator, and then select the emulator you'd like to deploy the app to:

    Select your Android emulator.

  6. In the Visual Studio toolbar, press the Start button to launch the app in your chosen Android emulator.

  7. 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.

    App running in the Android emulator.

Build and debug iOS apps

To build and debug .NET 6 iOS apps from Visual Studio 2022 you must manually install the .NET 6 SDK and iOS workloads on both Windows and macOS (your Mac build host).

If, while connecting Visual Studio to your Mac through Xamarin Mac Agent (XMA), you are prompted to install a different version of the SDK, you can ignore the prompt since it refers to a legacy version of XMA.

 Note

Visual Studio 2022 can only currently deploy .NET MAUI iOS apps to the iOS simulator, and not to physical devices.

No comments:

Post a Comment

How to register multiple implementations of the same interface in Asp.Net Core?

 Problem: I have services that are derived from the same interface. public interface IService { } public class ServiceA : IService { ...