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

 dyh81216462 发布于 2022-12-04 00:34

我正在尝试将Microsoft.AspNet.WebApiNuget包添加到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

具体的错误行如下.它似乎是在尝试添加对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.

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

错误截图:

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

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

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

    2022-12-11 03:08 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有