question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Net6.0-windows(Winform project) cannot be referenced by .NETCore-App,Version=6.0(Xunit project)

See original GitHub issue

Describe the bug

A clear and concise description of what the bug is. When I use an xunit project to test winform project, But it will throws a NU1201 error

To Reproduce

This bug is easy to reproduce. Just create a winform project and xunit via visual studio 2022, and then add winform project reference to xunit project.

Exceptions (if any)

NU1201	Project WinFormsApp1 is not compatible with net6.0 (.NETCoreApp,Version=v6.0). Project WinFormsApp1 supports: net6.0-windows7.0 (.NETCoreApp,Version=v6.0)
Project '..\WinFormsApp1\WinFormsApp1.csproj' targets 'net6.0-windows'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v6.0'.	TestProject1	C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets	1806	

Further technical details

  • Visual studio 2022 17.2.4
  • winform and xunit projects are both created by vs
  • dotnet sdk version 6.0.301

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

34reactions
Spydeecommented, Oct 31, 2022

I was able to resolve this by doing the following: Select the target project to test (the main app or a library usually) Press ALT-ENTER to open the project file. Note the version of windows being targeted.

Select the xUnit (or NUnit) test project. Press ALT-ENTER to open the project file. The Windows version is probably not selected. Select an OS to target.

That fixed the problem for me with NUnit and xUnit.

Spydee

2reactions
amilojkocommented, Jul 2, 2023

I was able to resolve this by doing the following: Select the target project to test (the main app or a library usually) Press ALT-ENTER to open the project file. Note the version of windows being targeted.

Select the xUnit (or NUnit) test project. Press ALT-ENTER to open the project file. The Windows version is probably not selected. Select an OS to target.

That fixed the problem for me with NUnit and xUnit.

Spydee

Oh gawd. This works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add reference project winform to my unit test ...
the solution is go to properties of the Unit Test project and change the target SO to Windows and version to 7. and...
Read more >
NU1201: xUnit project not compatible with .Net 5 WinForms ...
I have a .Net 5 WinForms Control library (Windows 10, Visual Studio 2019) and want to add some unit tests for the non-UI...
Read more >
Cannot Add Reference To XUnit Test Project
Usually test projects are created as standalone libraries. You don't add references to them. You just run the tests straight out of them ......
Read more >
Getting a "could not be found" from the unit test project
I've made some changes to a ASP.NET MVC Core (.NET 6) solution. There's two projects; the MVC project and a xUnit test.
Read more >
Getting started: .NET Core with command line > xUnit.net
Getting Started with xUnit.net. Using .NET Core with the .NET SDK command line. In this article, we will demonstrate getting started with xUnit.net...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found