Skip to content
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

Unit test projects can't reference MAUI projects #21209

Closed
Adam-- opened this issue Mar 14, 2024 · 3 comments
Closed

Unit test projects can't reference MAUI projects #21209

Adam-- opened this issue Mar 14, 2024 · 3 comments
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

Comments

@Adam--
Copy link
Contributor

Adam-- commented Mar 14, 2024

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

  1. Create a new MAUI project using Visual Studio
  2. Within the solution, add a new unit test project (xUnit, NUnit)
  3. Add a project reference form the unit test project to the MAUI project
  4. Attempt to build the unit test project

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:

  • add ;net8.0 to the TargetFrameworks
  • change the OutputType to <OutputType Condition="'$(TargetFramework)' != 'net8.0'">Exe</OutputType>
  • and if needed remove the compilation of MauiProgram.cs with
  <ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
    <Compile Remove="MauiProgram.cs" />
  </ItemGroup>

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

@Adam-- Adam-- added the t/bug Something isn't working label Mar 14, 2024
@ninachen03
Copy link
Collaborator

Verified this issue on VS 17.10.0 Preview 2. can repro it.

<style> </style>
Severity Code Description Project File Line Suppression State
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'. MauiApp3.Test C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets 1879  

@ninachen03 ninachen03 added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Mar 15, 2024
@mattleibow
Copy link
Member

Duplicate of #3552

@mattleibow mattleibow marked this as a duplicate of #3552 Mar 18, 2024
@Adam--
Copy link
Contributor Author

Adam-- commented Mar 18, 2024

@mattleibow, as I mentioned in the description, this is still happening and appears to be a regression. @ninachen03 reproduced it too.

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.

Could you please reopen this issue?

@github-actions github-actions bot locked and limited conversation to collaborators Apr 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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
Projects
None yet
Development

No branches or pull requests

4 participants