An error occurred while trying to restore packages. Please try again

帅比萌擦擦* 提交于 2019-11-30 10:53:59
Haacked
  1. Make sure you upgrade to the latest NuGet (http://docs.nuget.org/docs/start-here/installing-nuget).
  2. Make sure you're doing package restore "The Right Way" http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html

That should resolve the issue.

If you don't want the package, just double-click your packages.config, find the line which refers to the package you want to get rid of, and delete that line.

Then, if you do want the package you could probably just redownload it using nuget and it'd probably resolve itself.

This is how I fix my issue:

First I clear my Package Source:

Then second, make sure I have the right path source and click the available package source:

I had a similar issue with the Microsoft.Bcl.Build.1.0.14 NuGet package. My solution to this was to

  1. Close Visual Studio
  2. Remove the package folder with Explorer (or better only move it to another location)
  3. Start Visual Studio
  4. Go to the NuGet package manager and click Restore

I resolved the same issue by downloading the latest version of NuGet (really easy install, quick download): http://docs.nuget.org/docs/start-here/installing-nuget

(Definitely a beginner's answer here, but I'll leave it since I didn't find this anywhere else.) Make sure that nuget.org hasn't been unchecked from your package sources.

Tools. Options. Nuget package manager. Package sources. Ensure "nuget.org" is checked.

For me I cloned a solution (vs2015/NuGet3.4) that had a nuget dependency on a pre-release package that had been superceded. Nuget failed to restore the pre-release and wouldn't let me either uninstall or upgrade it. I frigged it by manually editting packages.config to target an older non-pre-release of the package, which I could then upgrade to the version I wanted. HTH

Just in case it helps someone else, I had this issue in a .NET Standard project where I had defined the target frameworks incorrectly:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netstandard1.3;netstandard2.0;net45</TargetFramework>
    </PropertyGroup>
    ...

When it should have been the plural TargetFrameworks (not TargetFramework):

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFrameworks>netstandard1.3;netstandard2.0;net45</TargetFrameworks>
    </PropertyGroup>
    ...

Go to TOOLS under OPTIONS select NuGet Package Manager

  1. General, Select Everything
  2. Package Source, Select all required Source

Hit OK. Done you must be good to go.

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