原文地址:https://www.jianshu.com/p/e452aa003dd5
如何为VS2010安装NuGet Package?
由于工作内容,需要使用RestSharp这个库。在安装好NuGet Package Manager之后,以为搜索后就可以安装。不知为何,无法从NuGet中查询在线数据。
![](http://upload-images.jianshu.io/upload_images/624674-d23c5e97c5231d72.png?imageMogr2/auto-orient/strip|imageView2/2/w/625/format/webp)
换成从命令行Package Manager Console中进行安装,提示如下的错误:
PM> Install-Package RestSharp -Version 105.2.3
The source at All [(Aggregate source)] is unreachable. Falling back to NuGet Local Cache at C:\Users\seewin\AppData\Local\NuGet\Cache
Install-Package : Unable to find version '105.2.3' of package 'RestSharp'.
At line:1 char:1
+ Install-Package RestSharp -Version 105.2.3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
检查NuGet Package Manager的配置:
![](http://upload-images.jianshu.io/upload_images/624674-b440ec9ceab48f67.png?imageMogr2/auto-orient/strip|imageView2/2/w/621/format/webp)
并没有发现什么异常。从网络中搜索了一些资料,给出的答案是Internet存在异常导致。参考https://github.com/NuGet/Home/issues/1325。
没找到答案,只能只能通过手动下载RestSharp进行安装。
版本选择
由于VS2010支持的.NET Framework最高版本为v4.0。目前,RestSharp的最新版本需要依赖.NET Framework 4.5.2:
![](http://upload-images.jianshu.io/upload_images/624674-5c96f937785dd1c4.png?imageMogr2/auto-orient/strip|imageView2/2/w/620/format/webp)
所以,为VS2010安装依赖时,要选择适当的安装包进行安装。由于不需要任何依赖,这里选择105.2.3这个版本进行安装:
https://www.nuget.org/packages/RestSharp/105.2.3
安装RestSharp
1、从NuGet下载RestSharp安装包:
![](http://upload-images.jianshu.io/upload_images/624674-12e80dd5e6acaec2.png?imageMogr2/auto-orient/strip|imageView2/2/w/1174/format/webp)
2、将安装包放到默认的本地目录:C:\Users\seewin\AppData\Local\NuGet\Cache
![](http://upload-images.jianshu.io/upload_images/624674-4317f0662f2f4bb7.png?imageMogr2/auto-orient/strip|imageView2/2/w/633/format/webp)
3、重新打开Package Manager Console,执行以下命令:
PM> Install-Package RestSharp -Version 105.2.3
PM> Install-Package RestSharp -Version 105.2.3
The source at All [(Aggregate source)] is unreachable. Falling back to NuGet Local Cache at C:\Users\seewin\AppData\Local\NuGet\Cache
Installing 'RestSharp 105.2.3'.
Successfully installed 'RestSharp 105.2.3'.
Adding 'RestSharp 105.2.3' to iDiary.
Successfully added 'RestSharp 105.2.3' to iDiary.
4、查看项目依赖引用:
![](http://upload-images.jianshu.io/upload_images/624674-7fb7c81d195df65c.png?imageMogr2/auto-orient/strip|imageView2/2/w/615/format/webp)
OK,RestSharp安装成功。
作者:辛未
链接:https://www.jianshu.com/p/e452aa003dd5
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。