Fix For “Package xxx is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0)”

怎甘沉沦 提交于 2020-01-14 12:47:46

问题


I created a blank solution with framework 4.6.1 and add a project core 2.0. This error show in output for many package 'Package xxx is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0)'. How Can I Fix it?


回答1:


Couple of things you could try to make it work, provided the packages that you are trying to install really do support .NET CORE 2.0.

  1. Make sure your VS is using NuGet 4.3 or greater. Within Visual Studio, go to Help -> About Visual Studio -> Notice the Nuget version and update if required.
  2. If this doesn't work you can try deleting the local packages cache, which most likely is at the following location:

    C:\Users{Your_User_Name}.nuget\packages

    and try restoring the packages again.

  3. If you still face the same problem, make sure your setup of .NET Core 2.0 SDK and VS2017 was entirely successful. If unsure, you can try reinstalling the same.

  4. Your last bet is tinkering with the package itself. As you would have guessed by now this is more of a hack than an actual solution. Go to the above mentioned location and find the package that's giving errors while restoring (a folder with the same name as the package). Within the package, find and edit the {Package Name}.nuspec file and add the following tag:

    group targetFramework=".NETStandard2.0"

    and add content to it by copying from the "group targetFramework=".NETStandard1.0" tag. Save and close. Open the lib folder within the same directory and create a copy of the netstandard1.0 folder and rename the copy as netstandard2.0

Hope this helps.




回答2:


Steps I tried before this (one of them may help someone else)

The solution that worked for me is below.

I spent a lot of time on this, and now (seemingly thanks to my nuget cache being in a happy state), I can create new projects without this issue!

I posted about this on reddit and tried many solutions:

  • I uninstalled all VS versions and all .NET Core SDKs that were installed (15.4 installs 2.0.2) and then downloaded VS2017 again from Microsoft and installed it. I still got the issue.
  • I checked my NuGet version (it was already the latest).
  • I had an old tooling preview of .NET Core SDK 1.0.1, so I removed that (after installing it again because the uninstaller was broken).
  • I removed my .nuget folder located at %userprofile%\.nuget.
  • My issue was with Netwtonsoft.Json 10.0.0, so I tried upgrading it but I couldn't install a newer version due to the same issue.
  • I tried everything that ThePretendProgrammer described. He was even kind enough to reply to my Reddit post.
  • I tried enabling the Activity Log for VS, but there was no conclusive evidence in the file.

Solution

But I fixed it! After lots of searching, I decided to search for the error code rather than the error message, I found this GitHub issue and followed hgrewa's advice.

If all of the above steps I tried didn't work for you, try following hgrewa's advice:

  1. It's probably best practice to clear your .nuget cache before doing this. I'm not sure it makes a difference, but let's be safe about it.
  2. Create an empty ASP.NET core project. Nuget restore will fail as we expect.
  3. Open NuGet manager and uninstall Microsoft.AspNetCore.All
  4. You may have to save and restart before the next step.
  5. Open the project again and install Microsoft.AspNetcore.All through NuGet. It's big so it might take a while to restore all of the packages.

You should now be able to create new web projects without this issue occurring. I hope this helps someone and saves you the 5-6 hours it has taken me to sort this out.



来源:https://stackoverflow.com/questions/46037274/fix-for-package-xxx-is-not-compatible-with-netcoreapp2-0-netcoreapp-version-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!