无法添加对'System.Net.Http'的引用.请确保它在全局程序集缓存中

Shi*_*iva 26 c# nuget asp.net-web-api

我正在尝试将Microsoft.AspNet.WebApiNuget包添加到C#类库项目中.这是项目源代码,以备您需要时使用.

当我在Visual Studio 2013中的Nuget包管理器控制台中执行以下命令时(其中包含最新的.NET 4.5)

PM> install-package Microsoft.AspNet.WebApi ErrandBoy.Web.Common
Run Code Online (Sandbox Code Playgroud)

我得到以下错误.

PM> install-package Microsoft.AspNet.WebApi ErrandBoy.Web.Common
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.WebHost (? 5.2.2 && < 5.3.0)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Core (? 5.2.2 && < 5.3.0)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Client (? 5.2.2)'.
Attempting to resolve dependency 'Newtonsoft.Json (? 6.0.4)'.
'Microsoft.AspNet.WebApi 5.2.2' already installed.
Adding 'Newtonsoft.Json 6.0.4' to ErrandBoy.Web.Common.
Successfully added 'Newtonsoft.Json 6.0.4' to ErrandBoy.Web.Common.
Adding 'Microsoft.AspNet.WebApi.Client 5.2.2' to ErrandBoy.Web.Common.
install-package : Failed to add reference to 'System.Net.Http'. Please make sure that it is in the Global Assembly Cache.
At line:1 char:1
+ install-package Microsoft.AspNet.WebApi ErrandBoy.Web.Common
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
Run Code Online (Sandbox Code Playgroud)

具体的错误行如下.它似乎是在尝试添加对Adding的引用'Microsoft.AspNet.WebApi.Client 5.2.2'

Failed to add reference to 'System.Net.Http'. Please make sure that it is 
in the Global Assembly Cache.
Run Code Online (Sandbox Code Playgroud)

我以前从来没有遇到过这样的错误.我确实在这个SO溢出问题上看到了类似的错误=> 安装ASP.NET Identity 2 Samples时出错,但是没有答案.

错误截图:

https://github.com/theShiva/ErrandBoy 未能添加对system.net.http nuget包web api错误的引用

Ada*_*abo 21

我刚才有同样的问题.我通过手动添加System.Net.Http到引用来解决它.然后它抱怨其他人,但在逐个手动添加后我能够用NuGet安装包.


Dan*_*ral 7

我遇到过同样的问题.我只是关闭了我的视觉工作室,然后再次启动它.此后安装包没有任何错误.