Search code examples
c#.netpackagenuget.net-standard

What's the reason for the weird error message "package is not compatible with netstandard2.0. Package does support netstandard2.0"?


We are getting weird error messages during our build.

They don't make any sense, because they are wrong (see MS documentation):

Error NU1202: Package XY 1.0.0 is not compatible with net48 (.NETFramework,Version=v4.8). Package XY 1.0.0 supports: netstandard2.0 (.NETStandard,Version=v2.0)

Error NU1201: Package XY 1.0.0 is not compatible with net6.0 (.NETCoreApp,Version=v6.0). Package XY 1.0.0 supports: netstandard2.0 (.NETStandard,Version=v2.0)

and the weirdest one:

Error NU1201: Package XY 1.0.0 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package XY 1.0.0 supports: netstandard2.0 (.NETStandard,Version=v2.0)

What is causing this behavior?


Solution

  • In our case, this was caused by referencing the same project once as a package and once as a project.

    It happened transitively:

    • Main Project -> Project 1 -> XY as package
    • Main Project -> Project 2 -> XY as project

    Solutions:

    • Referencing it only as a package (PackageReference)
    • or referencing it only as a project (ProjectReference)

    It's unfortunate, that Microsoft does not log a better error message, because it took us quite some time to find out what exactly the problem is.