Xamarin Forms Migration to MAUI - Build issues

Sreejith Sreenivasan 1,001 Reputation points
2023-08-15T15:18:38.6366667+00:00

I have migrated my Xamarin Forms app to a MAUI using upgrade assistant. First I converted the Solution then converted the Android and iOS projects.

After that I face a lot of issues when rebuilding the project.

  1. I have added the following to the ios project .csproj file for fixing the "doesn't have a target for 'net6.0-ios/ios-arm64'".
<PropertyGroup Condition="$(TargetFramework.Contains('-ios'))">
    <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>
  1. I have added the <SingleProject>true</SingleProject> property into my Android project's .csproj file under the first/main property group, closed VS, deleted Bin, Obj, .vs folders for fixing the android physical device availability issue.
  2. Set all of the files' build action to AndroidResource in the Resource folder on the Android platform and set BundleResource in the iOS platform.
  3. For fixing the below kind of Cannot resolve type errors, I set the Xaml build action to MauiXaml from Embedded Resource.

Error : XamlC error XFC0000 : Cannot resolve type "ContentPage". Error : XamlC error XFC0000 : Cannot resolve type "Frame". Error : XamlC error XFC0000 : Cannot resolve type "Application".

After all these fixes also I am facing some other build issues. I am adding it below:

  1. Severity Code Description Project File Line Suppression State Error NETSDK1136 The target platform must be set to Windows (usually by including '-windows' in the TargetFramework property) when using Windows Forms or WPF, or referencing projects or packages that do so. MyProject.iOS C:\Program Files\dotnet\sdk\7.0.306\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets 250
  2. Severity Code Description Project File Line Suppression State Error NU1107 Version conflict detected for Xamarin.AndroidX.Browser. Install/reference Xamarin.AndroidX.Browser 1.4.0.1 directly to project MyProject to resolve this issue. MyProject -> Microsoft.Maui.Dependencies 6.0.553 -> Xamarin.AndroidX.Browser (>= 1.4.0.1) MyProject -> Xam.Plugin.HtmlLabel 5.1.0 -> Xamarin.Essentials 1.7.0 -> Xamarin.AndroidX.Browser (>= 1.3.0.5 && < 1.4.0). MyProject E:\My Projects\Xamarin\MyProject-MyProject-app\MyProject\MyProject\MyProjectMyProject.csproj 1
  3. Severity Code Description Project File Line Suppression State Error NU1202 Package GMImagePicker.Xamarin 2.5.1 is not compatible with net6.0-ios16.1 (.NETCoreApp,Version=v6.0). Package GMImagePicker.Xamarin 2.5.1 supports: xamarinios10 (Xamarin.iOS,Version=v1.0) MyProjectMyProject.iOS E:\My Projects\Xamarin\MyProject-MyProject-app\MyProject\MyProject.iOS\MyProjectMyProject.iOS.csproj 1
  4. Severity Code Description Project File Line Suppression State Error APT2144 invalid file path 'E:\My Projects\Xamarin\MyProject-MyProject-app\MyProject\MyProject.Android\obj\Debug\net6.0-android\res\resources\xml_\file_paths.xml'. MyProjectMyProject.Android C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.485\tools\Xamarin.Android.Aapt2.targets 123
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,079 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,416 Reputation points Microsoft External Staff
    2023-08-29T09:44:55.2866667+00:00

    Hello,

    I check the references of your project, there are many third-party tools. And some NuGet packages don't support MAUI, for example NuGet Gallery | Rg.Plugins.Popup 2.1.0. Some do not support .net7, for example NuGet Gallery | Xam.Plugin.Media 6.0.2. Please try to remove these packages and try to find if there are other packages that can replace them. Or you could connect the owners to update the package.

    As described in the doc - Manually upgrade a Xamarin.Forms app to .NET MAUI - .NET MAUI | Microsoft Learn

    If you can't find a .NET 6+ compatible version of a NuGet package you should:

    • Recompile the package with .NET TFMs, if you own the code.
    • Look for a preview release of a .NET 6+ version of the package.
    • Replace the dependency with a .NET 6+ compatible alternative.

    In addition, it's recommended that you upgrade the project manually. You could create an empty MAUI project, then copy the file into it.

    Update

    I have added the styles on App.xaml.cs, but it is not reading.

    You could open the App.xaml file, there a default theme, and all styles can be set in "Resources/Styles/Styles.xaml". For more details, please refer to Theme an app - .NET MAUI | Microsoft Learn

    Xaml widget names are not reading on Xaml.cs pages.

    There might be some other errors in the page.xaml, so the element cannot be read. Or this is a compilation error, you could try to clean the bin/obj folder, re-open VS and re-build the app.

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.