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

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

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

 PM> install-package Microsoft.AspNet.WebApi ErrandBoy.Web.Common 

我收到以下错误。

 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 

具体的错误行如下。 它似乎是在尝试添加对'Microsoft.AspNet.WebApi.Client 5.2.2'添加'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. 

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

错误截图:

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

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

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

我只是通过在项目设置中将.Net框架版本更改为4.6.1来解决它。 然后我成功地安装了所有东西。

是否从包管理器控制台安装并且它完成了诀窍。