Search code examples
windowsmaui.net-8.0

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


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.

We updated the dotnet version, installed the SDK for .Net8 and updated the nuget packages, and 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, and tested with Blazor dotnet 8.

The issue only persists if trying to run the project using the default build/run options from Visual Studio. We can (sometimes) work around issue by building and running the project using the CLI, that I will talk about later. The problem with this is debugging is not available.

One error we're getting is obj/project.assets.json doesn't have a target for net8.0-android. Sometimes, after deleting the bin and obj folders 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

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 this is there a chance the project will run.

Another error we get 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.

Running a default MAUI project on the same Windows machines has no problems, so I'm guessing the problem could be project related.

This was working well in .Net 7.0.101, but now immediately after updating to 8.0.3 we cannot reliably build or debug the project in Windows.

We have tried too many ways to build/run the project on NET8.0 to list them all here, but they all result in errors (mainly saying that we are not targeting .NET8.0 for Android). The only way to actually build and run the project (not in debug mode) is with the following command:

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

How can we fix this?


Solution

  • The problem is with a nuget package for iOS that generates a long path problem which VS for windows doesn't know how to handle. You can either remove the Xamarin.Firebase.iOS package or change your target framework to only target iOS when building from a machine that is not windows.

    I managed to workaround the issue by deleting net8.0-ios from TargetFrameworks and adding this line instead:

    <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))=='false'"> $(TargetFrameworks);net8.0-ios</TargetFrameworks>