Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET Standard 2.0 class library, that references a .NET Framework 4.7.1 class library with PackageReference fails #1755

Closed
splusq opened this issue Nov 17, 2017 · 10 comments
Milestone

Comments

@splusq
Copy link

splusq commented Nov 17, 2017

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?

@livarcocc
Copy link
Contributor

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.

@livarcocc
Copy link
Contributor

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?

@emgarten
Copy link
Member

@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?

@splusq
Copy link
Author

splusq commented Nov 20, 2017

Here's a sample: https://github.com/splusq/exp/tree/master/NU1201

@splusq
Copy link
Author

splusq commented Nov 20, 2017

@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.

@splusq
Copy link
Author

splusq commented Nov 22, 2017

@emgarten @livarcocc thoughts?

@emgarten
Copy link
Member

@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

@livarcocc livarcocc added this to the Discussion milestone Nov 22, 2017
@livarcocc
Copy link
Contributor

@splusq Does this answer your questions?

@splusq
Copy link
Author

splusq commented Nov 23, 2017

it does - thanks @emgarten and @livarcocc

@MDKimzey
Copy link

MDKimzey commented Dec 8, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants