Bala
Bala

Reputation: 11

MAUI Project is not compatible with net7.0 when I try to build it on windows but it builds on mac

I have a solution with 2 projects and a unit test project in it. When I try to build it in my windows machine, I get the following error message

Error NU1201: Project SampleProject is not compatible with net7.0 (.NETCoreApp,Version=v7.0). Project SampleProject does not support any target frameworks. This error is from the test project - SampleProject.Tests

What is the cause of this issue? If I remove .net7-0 from the targetframework of my projects, the app builds without building test project. How do I fix this?

Upvotes: 0

Views: 2394

Answers (2)

Liqun Shen-MSFT
Liqun Shen-MSFT

Reputation: 8090

I recommend you refer to the MauixUnitTestSample sample code and watch the awesome Unit Testing tutorial by Gerald Versluis.

Though the tutorial is about .NET6, it also applies to .NET7.

To sum up,just make some changes to maui project file:

1.Add net7.0 to TargetFrameworks

<PropertyGroup>
    <TargetFrameworks>net7.0;net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>

2.Change this line:

<OutputType>Exe</OutputType>

to

<OutputType Condition="'$(TargetFramework)' != 'net7.0'">Exe</OutputType>

If you still have any questions, free to ask me.

Hope it helps!

Upvotes: 3

benjamin.fehr
benjamin.fehr

Reputation: 33

To fix this issue, you will need to select a compatible target framework for the "SampleProject" project to use. If you want this project to run with the test project, you will also need to set the target framework for the "SampleProject.Tests" project to the same framework. You can do this by opening the project properties and changing the target framework in the "Application" tab of the project settings. If you are using Visual Studio, you can right-click on the project -> Properties -> Application -> Target framework dropdown. If you are using .NET CLI, you can update the target framework in the project file (e.g., SampleProject.csproj).

Upvotes: -2

Related Questions