The first project with .NET MAUI

The first project with .NET MAUI

14 June 2021

.NET MAUI/Xamarin

Buy Me A Coffee

Hello!

Today we will migrate an existing Xamarin.Forms Application to .NET MAUI! As a victim I chose my KanbanBoard app.

Installation

First of all, we need to verify if we have prepared the development environment. One of the tools for that is MAUI Check. Run the next commands in PowerShell:

It will automatically attempt to fix any issues, but I highly recommend using the Visual Studio installer.

Solution Configuration

  1. Edit solution file

  • Remove Platform-specific projects;

  • Remove unused Solution Configuration Platforms

The base solution configuration is done.

It's project time

.NET MAUI introduces the Single project concept, SDK-project style, and much more. Let's first migrate our platforms to the "Shared" project.

  1. Create the "Platforms" folder in the "Shared" project. Then for each platform create a folder in the "Platforms" project:

  • Android

  • iOS

  • MacCatalyst

  • Windows

  • Tizen

1.1. Android

  • Copy AndroidManifest.xml, MainActivity.cs, MainApplication.cs, all your services, Resources folder to the Android folder.

1.2. iOS, macOS

  • Copy Main.cs, Info.plist, Entitlements.plist, AppDelegate.cs, and all your services to the iOS/MacCatalyst folder.

1.3. Windows

  • Copy Package.appxmanifest, App.xaml, App.xaml.cs, app.manifest to the Windows folder.

1.4. Tizen

  • Copy Main.cs, tizen-manifest.xml to the Tizen folder.

  1. Delete Old platforms project folders.

  2. Now we need to modify and change these files

  • From AndroidManifest.xml remove the package name, version code, and version name. We will set these settings later in csproj file.

  • Replace MainActivity.cs content with:

  • Replace MainApplication.cs content with:

  • Replace AppDelegate.cs content with:

  • Replace App.xaml from Windows folder with:

  • Replace App.xaml.cs from Windows folder with:

  • Replace Package.appxmanifest content with the next:

  • Replace Main.cs from Tizen folder with:

  1. Replace all Xamarin.Forms with Microsoft.Maui (somewhere you may need to add Microsoft.Maui.Controls

  2. Replace App.xaml.cs file content in the root folder with the next code:

  1. Create MauiProgram.cs with content:

  1. Replace xmlns="http://xamarin.com/schemas/2014/forms" with xmlns="http://schemas.microsoft.com/dotnet/2021/maui"

  2. Finally update csproj file with:

Pay attention to the last ItemGroup. .NET MAUI is integrated with Resizetizer NT, so MauiImage and MauiFont will automatically prepare resources for all your applications.

Build and Run

Issues

1. Android deployment (Solved)

I was not able to deploy the application to the device until specified the RuntimeIdentifiers for Android. Add this line to the PropertyGroup in your csproj file:

2. iOS Device deployment (Solved)

I was not able to deploy the application to the device until specified the RuntimeIdentifiers. Add this line to the csproj file:

3. Windows release (Solved)

To generate the Appx file add the next code to the csproj file:

The final result:
Kanban MAUI

You can find the code changes on GitHub

Buy Me A Coffee

Related:

Create a gallery app using .NET MAUI Blazor

Create infinite scrolling gallery app using .NET MAUI Blazor. Replicate Google Photos and Instagram Gallery UI.

Creating dynamic floating action button

Create a dynamic floating action button using an Expander control.

An unhandled error has occurred. Reload

🗙