4

I am having MAUI project and platform specific code for Android and Windows. When I reference the MAUI project to xUnit project in Visual Studio 2022 Preview, it shows an error saying "project is not compatible to net6.0", as the MAUI project references target frameworks "net6.0-android and net6.0-windows".

Is there any way introduced so that I can reference the MAUI project and unit test platform specific code?

1
  • Since the xunit project message is complaining about compatibility with net6.0, perhaps google xunit .net 6 for suggestions? The problem might have nothing to do with maui... Commented Apr 22, 2022 at 16:16

2 Answers 2

1

A stock "net6.0" xUnit test in Visual Studio cannot reference net6.0-android and net6.0-iOS libraries, etc. I have seen that your MAUI app can be modified to multi-target net6.0. See https://www.youtube.com/watch?v=C9vIDLQwc7M for a tutorial.

For running tests with platform-specific code, I've had reasonable success with https://www.nuget.org/packages/Shiny.Xunit.Runners.Maui, to run on actual mobile devices. The xUnit team has made runners for Xamarin.Forms in the past - I don't know if at some point they will start to maintain them for MAUI or not.

Sign up to request clarification or add additional context in comments.

Comments

0

I came across this same issue using xUnit and .NET 8.0

While it is possible to target net6/7/8.0 in the MAUI project and then have your tests reference that, it may not always be that simple.

My MAUI project used Grial from UXDivers and trying to target net8.0 created a large amount of errors as the Grial NuGet does not target net8.0

After much thought, the only way to solve this issue would be to move everything from the MAUI project which requires testing to a new net8.0 project which can then be referenced from the MAUI project and the test project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.