'create unit tests for .net 6.0

I created a .Net 6 class library and now I am trying to create a test project.
a .net 6 test project is not available. Online I found the information to use .Net Framework or .Net core in order to test.

I created a .Net Framework 4.8 test project an referenced my class library.

I receive the Compiler error:

Project '..\CircularList\CircularList.csproj' targets 'net6.0'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.8'. UnitTests

How do I do Unit tests then? Is there any way to target .Net 6.0 from .Net Framework 4.8?



Solution 1:[1]

I guess that must have been the answer. Don't use the project template "Unit Test Project (.NET Framework)" if you want to use test a .net6 library.

Use a more up-to-date template in the project creation wizard. There are newer MSTest ones, but one could also take advantage of better templates like the xUnit one.

Solution 2:[2]

I created a NET 6.0 class library and received the same message.

I went into properties, just to double check that my project and my test project were set the same and noticed that the Target OS was not set in my library.

It was in my project, but not in my class library.

Once I changed my class library "Target OS" - to be windows, the same as my project, the error messages went away.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nathan Cooper
Solution 2 Kennetic