maui icon indicating copy to clipboard operation
maui copied to clipboard

After migrating to .NET8, mobile app has issues building on Visual Studio only on Windows

Open sergiu017 opened this issue 2 years ago • 2 comments

Description

After migrating a MAUI project from .NET7 to .NET 8, the app only builds and runs on the macOS version of Visual Studio. The app targets Android and iOS platforms for net8.0. After updating the dotnet version, installing the SDK for .net8 and updating the nuget packages we had no problem building and running the project on both android and ios emulators, but only on macOS Visual Studio.

After trying to run the same exact project on windows(Visual Studio 17.8.4) we are getting all kinds of errors. We have ensured that the SDK for dotnet8 is installed on the windows machines, that being tested on blazor dotnet 8.

The issue only persists if trying to run the project using the default build/run options from visual studio. We have found a workaround that's able to run the project using the CLI, that I will talk about later. The problem with this is that, even if it runs, debugging is not available.

One of the errors that we're getting is that in obj/project.assets.json doesn't have a target for net8.0-android. Sometimes, after deleting the bin and obj folders of the project and running dotnet restore, the error goes away and we're able to build from the CLI.

Running dotnet build from the CLI shows no errors but trying to build from visual studio throws a lot of errors, sometimes even hundreds. The way we managed to run the app on emulators/physical devices was by running the command

dotnet build -t:Run --framework net8.0-android

But even then, it might throw some errors regarding the targeting version if we don't delete the bin and obj folders/clean the project and then restore the nuget packages. Only after doing all of that there is a chance the project will run.

Another error we're getting while trying to run the project from visual studio is that the AndroidManifest file does not exist, even though the project contains that file. Also, we are getting a lot of errors for types or namespaces that are not found. Some of these are present even for default MAUI classes such as ContentPage.

Also, running a default MAUI project has no problems even on Windows, so I'm guessing the problem could be project related and not a visual studio problem?

Steps to Reproduce

  1. Open a .NET MAUI project targeting version 7.
  2. Change the targeting versions from net7.0 to net8.0
  3. Update the nuget packages
  4. Clean and restore the project
  5. Try to build/run the project on Windows Visual Studio

Link to public reproduction project repository

No response

Version with bug

8.0.3

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

7.0.101

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

The only workarounds we found were either using Visual Studio for macOS or running the program through the CLI, with the command mentioned above.

Relevant log output

No response

sergiu017 avatar Jan 17 '24 08:01 sergiu017

Update: The issue seems to be related to Xamarin.Firebase.iOS nuget package. After getting rid of those we managed to build and run the project with no problems. This issue still only affects the windows version of VS. On macOS on the other hand, the package seems to work fine. We're using it for push notifications and they are working on both iOS and Android emulators and physical devices.

sergiu017 avatar Jan 18 '24 11:01 sergiu017

Update 2: Fixed the issues by removing net8.0-ios from TargetFrameworks and adding a conditional target framework based on the OS: <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))=='false'"> $(TargetFrameworks);net8.0-ios</TargetFrameworks>

This is still only a workaround though and it should be possible for the project to build on iOS platform even on windows.

sergiu017 avatar Jan 19 '24 09:01 sergiu017

Duplicate of #19946

PureWeen avatar Jan 26 '24 16:01 PureWeen