Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '

I am trying to reference a nuget package which is clearly .NetStandard2.0. We own the source code for this package and written it to target .netstandard. We do have a CI pipeline so that when we push this code, it builds and releases the nuget package. When I try to reference the resulting nuget package into my current .netCore application, i get following error:

was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project.

That does not make any sense to me. So far I have tried following debugging steps:

  • Referenced the source code directly as a project reference to my project. Which did work all fine.
  • Analyzing resulting nuget package in dotpeek to make sure that it in fact is a .netstandard package and it is.

Not sure what makes it think that it was targeting at any point. below is how my .csproj configuration looks like

<TargetFramework>netstandard2.0</TargetFramework>

Not sure if any other config block matters here but let me know if you need more info on this. Any ideas?

like image 543
Lost Avatar asked Feb 21 '19 22:02

Lost


4 Answers

I ran in to a similar issue where I was publishing my own NetStandard2.0 package via Azure Artifacts and then attempting to consume it in a netcore application.

It turned out that the problem was that I had named my package the same as an existing NuGet package. My Azure Artifacts nuget feed was configured correctly in Visual Studio, but when it attempts to install the package it tries the default NuGet feed first and picks up the other one (which happened to be NetFramework only) rather than mine.

Once I renamed my package to be unique (I just added my own namespace) and re-published it all worked properly.

I guess that might not be the issue for everyone but it was for me.

like image 186
TomP Avatar answered Oct 16 '22 23:10

TomP


I ran into this issue as well. In my case, when the DLL was packaged and placed in the lib/ folder, the import warning occurred. It was solved by placing the packaged DLL in the lib/netstandard2.0 folder.

like image 38
Chronogeran Avatar answered Oct 16 '22 23:10

Chronogeran


You have to use every packages in your project compatible with .NETCoreApp,Version=v2.0.

There should be some package name before "was" in your error message. For ex:

Package 'Microsoft.AspNet.WebApi.Client 5.2.2' was restored
Package 'EntityFramework 6.2.0' was restored 
like image 3
cdev Avatar answered Oct 16 '22 23:10

cdev


I had the same problem. To fix this

  1. Look in VS2019 under dependencies / Packages.
  2. Then look for the packages with the warning sign next to them.
  3. Goto your windows profile directory and delete the corresponding folder under .nuget
  4. Delete the reference under dependencies / Packages
  5. Add the Nuget package via Manage Nuget Packages for solution
like image 2
Nigel Findlater Avatar answered Oct 17 '22 00:10

Nigel Findlater