Home: Cannot install NuGet package depending on Microsoft.NETCore into .NET Framework 4.6 console application project

Created on 5 Jan 2016  路  10Comments  路  Source: NuGet/Home

I am not sure if this is directly related to NuGet or an issue with the underlying packages but this seems like the first sensible place to report it. Please let me know if this issue is better off getting raised elsewhere.

I create a new portable class library project using VS 2015, selecting UWP and .NET 4.6 as the targets. I build the created project and package the assembly into a NuGet package with the DLL file in lib\dotnet. I define Microsoft.NETCore version 5.0.0 as the only dependency.

I then try to install this NuGet package in a new .NET Framework 4.6 console application project - just the basic Visual Studio project template, no customization.

Expectation:

NuGet package is successfully installed, together with the .NET Core dependencies.

Reality:

Could not install package 'Microsoft.NETCore.Platforms 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Workaround:

If I cherry-pick the individual dependencies below Microsoft.NETCore that my library needs (in case of an empty library, none, but it works with e.g. System.IO.FileSystem if I add code using it) then the package installs successfully. However, this is very tedious and I would much prefer to just reference .NET Core directly.

Most helpful comment

guys it might be crystal clear to you what's going on, for lots of other people who is never an expert of NuGet to understand all these black magic, anyone bother to explain a bit more? (or one must be expert of NuGet to survive as a .NET dev?) Yes you may argue it is because the expanded surface .NET is supporting, while it is true I was still wondering does a Java dev also need to go through similar things given Java is even more ubiquitous?

1, why is a console 461 not happy with "Microsoft.NETCore.Platforms 1.0.0"?
2, suppose today I'm doing the same thing as @sandersaares, i.e.

I create a new portable class library project using VS 2015, selecting UWP and .NET 4.6 as the targets. I build the created project and package the assembly into a NuGet package with the DLL file in lib\dotnet. I define Microsoft.NETCore version 5.0.0 as the only dependency.

Even with NuGet 3.5.0.1520, it still gives the same error msg, so what do you guys really mean this is solved? Are you implying that one should stop doing the above and create new library targeting .netstandard1.3 instead? If so, why not say it in the format as a mini Q&A, so that who ever landed on this page later by Google can find what they want, other than carry on stay in the dark?

All 10 comments

CC @ericstj @emgarten

@sandersaares your workaround is the correct approach. We're working on making this easier in future releases.

You can try this tool which helps find the correct dependencies: https://github.com/onovotny/ReferenceGenerator

Aha. I would like to understand this a bit more, as the fact that the workaround is the correct approach is rather surprising to me. What is the reason for not being able to reference Microsoft.NETCore directly in this fashion? It is not immediately obvious to me - seems like a fairly standard case to just declare "I want .NET Core" in the dependencies.

This is going to get resolved when we implement the netstandard TFM. So your approach is correct because the metapackage prevents the dependencies from being installed into the 4.6 project

I'm closing because this should be handled as soon as netstandard is out (and it is already coded in 3.4),

Install-Package : Could not install package 'Microsoft.Spatial 6.15.0'. You are trying to install this package into a project that targ
ets '.NETFramework,Version=v4.5', but the package does not contain any assembly references that are compatible with that framework. For
more information, contact the package author.
At line:1 char:16

getting this error while installing Microsoft.Odata.Client. I am using visual studio 2012. How to resolve this ?

guys it might be crystal clear to you what's going on, for lots of other people who is never an expert of NuGet to understand all these black magic, anyone bother to explain a bit more? (or one must be expert of NuGet to survive as a .NET dev?) Yes you may argue it is because the expanded surface .NET is supporting, while it is true I was still wondering does a Java dev also need to go through similar things given Java is even more ubiquitous?

1, why is a console 461 not happy with "Microsoft.NETCore.Platforms 1.0.0"?
2, suppose today I'm doing the same thing as @sandersaares, i.e.

I create a new portable class library project using VS 2015, selecting UWP and .NET 4.6 as the targets. I build the created project and package the assembly into a NuGet package with the DLL file in lib\dotnet. I define Microsoft.NETCore version 5.0.0 as the only dependency.

Even with NuGet 3.5.0.1520, it still gives the same error msg, so what do you guys really mean this is solved? Are you implying that one should stop doing the above and create new library targeting .netstandard1.3 instead? If so, why not say it in the format as a mini Q&A, so that who ever landed on this page later by Google can find what they want, other than carry on stay in the dark?

A year of silence.

C:gitinternal>NuGet.exe restore .\MainTrunkxxx.sln
MSBuild auto-detection: using msbuild version '15.4.8.50001' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'.
Restoring NuGet package Microsoft.NETCore.Platforms.2.0.0.
Errors in packages.config projects
Unable to find version '2.0.0' of package 'Microsoft.NETCore.Platforms'.

So still no solution or fix?

I am using nuget 4.4.1

Another year and still no resolution?

Was this page helpful?
0 / 5 - 0 ratings