Sdk: .NET Standard 2.0 class library, that references a .NET Framework 4.7.1 class library with PackageReference fails

Created on 17 Nov 2017  路  10Comments  路  Source: dotnet/sdk

I have a .NET Standard 2.0 class library, that references a .NET Framework 4.7.1 class library (works fine)

However, if the .NET Framework 4.7.1 adds a PackageReference (new style), I get the following error (possibly due to transitivity):

Error NU1201 Project ClassLibrary2 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Project ClassLibrary2 supports: net471 (.NETFramework,Version=v4.7.1)

The package in question being added can be any package, packages that have support for .NET Standard or otherwise, the same error.

What am I missing?

All 10 comments

I think this is likely just triggering a restore and causing the failure. A netstandard library referencing a full framework library is not supported. It is like getting a library that targets a specification to depend on a implementation.

Only the other way around is possible: net471 referencing netstandard2.0. I would suggest that if you can't make your net471 library simply target netstandard2.0, that you multi-target then using net471;netstandard2.0.

Just to be correct, the last one of these we allowed was for netstandard2.0 to reference net461. Above that, it is not possible.

@rrelyea @emgarten it seems NuGet is permitting netstandard2.0 libraries to directly reference net471 projects as long as the net471 project is an old style csproj. Can you guys take a look?

@splusq can you share a simple solution that repros this? A github repo would be easiest.

Adding a PackageReference should not change compatibility rules.

Also, what version of dotnet CLI are you using?

@livarcocc if you look at the sample https://github.com/splusq/exp/tree/master/NU1201 -- if I move the Newtonsoft reference from ClassLibary2 to 1 it works.

@emgarten @livarcocc thoughts?

@splusq since ClassLibrary2 is a standard csproj that isn't a NETCore SDK project like ClassLibrary1, removing the PackageReference means that it no longer uses nuget at all. For old style non-nuget projects restore skips the compatibility check.

As for the actual compat error, this looks correct to me. See @livarcocc's answer for ns2.0 -> net471 compatibility

@splusq Does this answer your questions?

it does - thanks @emgarten and @livarcocc

I had the same issue. However, I was able to build when I given Builder privileges. I did not have to remove any PackageReference.

Was this page helpful?
0 / 5 - 0 ratings