-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to create XUnit Project referencing .NET 8 MAUI #21138
Comments
This is not a bug with MAUI, the error you're getting is correct for what you're doing. See #17791 (comment) The XUnit project is If you want to test platform specific code, you would need an XUnit test runner that would run the code on the platform in question. If you want to test generic cross-platform code and don't need it running on the platform, then you would need to move that into another class library so you could reference it inside the generic XUnit (or whatever .NET Test framework) you have. You could also change your MAUI csproj to add the target framework <TargetFrameworks>net8.0;net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
<OutputType Condition="'$(TargetFramework)' != 'net8.0'">Exe</OutputType> The key is making sure that the generic code doesn't have the output type of an exe, since it can't be run that way. @PureWeen @BretJohnson Do you have any other advice? |
Thank you. Adding net8.0 to the target frameworks does indeed work and adding a conditional output, however it then breaks visual studio for me. If I use Rider, I'm able to compile successfully and run my tests. The downside is I obviously lose visual studio and its UI for publishing ad hoc builds. I have however found the command line to publish, so it's a bit of a manual task which I'm willing to do if I can actually test my business logic which is more important. |
Can you elaborate on "breaks visual studio"? |
Sorry, was a rushed reply. I get the following errors in the Errors tab which prevents me from building, however Rider is fine.
And then several errors which are the same:
If i then look at the Dependencies in the solution explorer, all of them except net8.0-android shows a yellow triangle. No matter how many times I run Clean and Rebuild, I get the same issues. I've even tried running |
Duplicate of #17791 |
@owenashurst if you use devkit with vscode do you get the same exception? |
This is because the app TFMs are setting a project version property using the ApplicationVersion, however, plain .net 8 does not have this concept. You need to also add a However, this still does not mean that this is the best way to do testing. It is much better to create a shared project that just has testable items in it - pages, VMs and models. Then make that be multi-targeted. Both the app and unit test project can then reference this singe shared project. |
Description
Whenever I try and create an XUnit project targeting my .NET 8 MAUI project, the IDE shows the following error:
Severity Code Description Project File Line Suppression State Details
Error NU1201 Project MyMauiApp is not compatible with net8.0 (.NETCoreApp,Version=v8.0). Project MyMauiApp supports:
Steps to Reproduce
1.) Create a .NET 8 MAUI project
2.) Create an XUnit test project
3.) Reference the .NET MAUI project from the XUnit Project
4.) Observe the error
Link to public reproduction project repository
No response
Version with bug
8.0.6 SR1
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, macOS, Other (Tizen, Linux, etc. not supported by Microsoft directly)
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response
The text was updated successfully, but these errors were encountered: