...

/

Converting .NET Framework Project to .NET SDK Style

Converting .NET Framework Project to .NET SDK Style

Learn how to convert a Xamarin.Forms project to .NET MAUI.

Xamarin.Forms was a predecessor of .NET MAUI. However, MAUI aims to completely replace it; therefore, it's important to know how to convert a Xamarin.Forms application to an MAUI application.

In this lesson, we'll cover the process of converting a Xamarin.Forms project file to an MAUI format. We'll demonstrate this with the help of the following setup. In this setup, we have two project folders: XamarinAppDemo and MauiConversionDemo. The XamarinAppDemo folder represents a multipart Xamarin.Forms application. It contains a project with Android-specific components and a project with cross-platform Xamarin.Forms components. The MauiConversionDemo project is a single-project MAUI application that was created by converting Xamarin.Forms project.

using System;

using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.OS;

namespace XamarineAppDemo.Droid
{
    [Activity(Label = "XamarineAppDemo", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
        }
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
}
Xamarin.Forms project converted into .NET MAUI format

Creating an SDK project

.NET MAUI uses the so-called SDK project format, while Xamarin.Forms uses a mixture of SDK-style projects and old-style .NET Framework projects. The old-style projects ...