Unable to restore / remove / update a NuGet packag

2020-05-30 08:36发布

I'm trying to give the SignalR Sample a test drive but it seems it references an old version of SignalR which is no longer available. The actual problem is that NuGet cannot remove the unavailable package without first restoring it !!!

PM> Install-Package Microsoft.AspNet.SignalR
Install-Package : Some NuGet packages are missing from the solution. The packages need to be restored in order to build the dependency graph. Restore the packages before performing any operations.
At line:1 char:1
+ Install-Package Microsoft.AspNet.SignalR
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetMissingPackages,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Then there will be a Restore button on the Package Manager Console which pressing it will result in the following error:

An error occurred while trying to restore packages: Unable to find version '2.1.0-pre-131116-b279' of package 'Microsoft.AspNet.SignalR.Client'

How can I install a newer version of an addressed package if the current version can not be found?

I'm using:

Microsoft Visual Studio Community 2015
Version 14.0.24720.00 Update 1
Microsoft .NET Framework
Version 4.6.01038
NuGet Package Manager   3.3.0

[UPDATE]

When I try to uninstall the troublesome package:

PM> Uninstall-Package -Id Microsfot.AspNet.SignalR -RemoveDependencies -Force
Uninstall-Package : Some NuGet packages are missing from the solution. The packages need to be restored in order to build the dependency graph. Restore the packages before performing any operations.
At line:1 char:1
+ Uninstall-Package -Id Microsfot.AspNet.SignalR -RemoveDependencies -F ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Uninstall-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetMissingPackages,NuGet.PackageManagement.PowerShellCmdlets.UninstallPackageCommand

5条回答
神经病院院长
2楼-- · 2020-05-30 08:59

Mentioned by @ferarias in a comment - if you are using nuget.exe, try updating it or downloading the latest version.

For me, upgrading from v4.4.1 to v4.6.2 was enough to fix the Some NuGet packages are missing error.

查看更多
你好瞎i
3楼-- · 2020-05-30 09:04

In my case, I'd restarted visual studio. Then I'd removed nuget package entry from package.config.

After that I was able to restore the dependency.

查看更多
Juvenile、少年°
4楼-- · 2020-05-30 09:14

You can manually remove the dependency by:

  1. Close Visual Studio (not a hard requirement, but helpful)
  2. In text editor, remove dependency from packages.config
  3. Remove package from packages/ directory
  4. In text editor, remove all references to package from .csproj file
  5. Start Visual Studio
  6. Reinstall package through NuGet
查看更多
甜甜的少女心
5楼-- · 2020-05-30 09:18

What works for me is:

1. Go to the packages.config file,

2. Find "... id="Microsoft.AspNet.SignalR.Client" version="" targetFramework="net45"..."

3. Change to an existing version, say "2.2.0".

4. Save.

5. Go to Nuget, and update to the latest.

查看更多
SAY GOODBYE
6楼-- · 2020-05-30 09:25

There's an easier solution, if you know the versions that currently exist in the feed. This solution can fix every package in every project.

  • Open packages.config file (if you have more than one project, do this for every packages.config file)
  • Update versions to the correct ones (i.e. change the version attribute)
  • In the Package Manager Console, type Update-Package -Reinstall

Hope it helps

查看更多
登录 后发表回答