Unit test projects can't reference MAUI projects #21209
Labels
platform/android 🤖
platform/iOS 🍎
platform/macOS 🍏
macOS / Mac Catalyst
platform/windows 🪟
s/triaged
Issue has been reviewed
s/verified
Verified / Reproducible Issue ready for Engineering Triage
t/bug
Something isn't working
Description
Given a solution with a MAUI project and a unit test project, when the unit test project has a project reference to the MAUI project, I get a build error:
Project '..\MauiApp3\MauiApp3.csproj' targets 'net8.0-android;net8.0-ios;net8.0-maccatalyst;net8.0-windows10.0.19041.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v8.0'.
In #3552, @mattleibow mentioned that it was fixed in .NET 8 preview 2 and closed the bug, however, it is not working with 8.0,200 or 8.0.202, VS 17.9.3 or VS 17.10.0 Preview 2.0. I marked this as a regression, but I didn't attempt to validate that it worked in .NET 8 preview 2.
In his screenshot on the linked bug, he was unit testing a class library. I tried both a MAUI app and class library and got the same error.
Steps to Reproduce
Observed behavior:
Error: Project '..\MauiApp3\MauiApp3.csproj' targets 'net8.0-android;net8.0-ios;net8.0-maccatalyst;net8.0-windows10.0.19041.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v8.0'.
Link to public reproduction project repository
https://github.com/Adam--/MauiUnitTestReferenceIssue
Version with bug
8.0.7 SR2
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.0-preview.2.7871
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?
Yes!
To the MAUI app csproj:
;net8.0
to theTargetFrameworks
OutputType
to<OutputType Condition="'$(TargetFramework)' != 'net8.0'">Exe</OutputType>
I didn't need to do this last part on the example project, but on a project with handlers, I needed to.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: