2

I am using Visual Studio 2022 targeting .NET6 Windows using WPF When I added Nunit test, I selected .NET 6 as the target. When I add using WPF2022ht4fEditor to my Nunit test I get the error

Project '..\WPF2022ht4fEditor\WPF2022ht4fEditor.csproj' targets 'net6.0-windows10.0.17763.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v6.0'

If I remove the using statement, it compiles fine.

How do I fix this?

By the way, I recognize that the problem is that my Nunit test is targeting .NET version 6 and that the application is targeting net6.0-windows. The app .csproj is

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>`

The issue is that I can't find a way to change them so they match. For instance, if I change the .csproj file for the app and set the TargetFramework to net6.0, I get a different error.

1
  • Your test and target projects need to match on compile target. Take a look at what' yoj have set in your csproj xml. Commented Aug 11, 2022 at 19:44

1 Answer 1

4

The solution turned out to be extremely simple - change the Unit test to windows

The sequence is Open Solution Explorer and right click the solution and select "Add" then "new project" Select Nunit Test Project that runs on ".NET Core on Windows, Linux, and MacOS" Select Next Name the Unit test project and click Next Accept the .NET6.0 Framework option and click Create

Once the Unit test project is loaded, right-click the Unit test project Scroll to find Target OS Select Windows

Now you can add the project you want to test. Right Click on "Dependencies" under the test project Select "Add project reference" Select the project to test and press OK Add "using MyProject" (where MyProject is the name of the project to test)

Note: a reload may be necessary. Close the solution and start it again.

Dave

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

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.