如何通过NuGet安装旧版本的软件包?

本文翻译自:How to install an older version of package via NuGet?

I want to install an older version of a package ( Newtonsoft.Json ). 我想安装一个旧版本的软件包( Newtonsoft.Json )。 But NuGet rolls back. 但NuGet回滚。

PM> Install-Package Newtonsoft.Json -Version 4.0.5
Successfully installed 'Newtonsoft.Json 4.0.5'.
Install failed. Rolling back...
Install-Package : Already referencing a newer version of 'Newtonsoft.Json'.

Any help will be greatly appreciated. 任何帮助将不胜感激。


#1楼

参考:https://stackoom.com/question/gp4M/如何通过NuGet安装旧版本的软件包


#2楼

try the following: 尝试以下方法:

Uninstall-Package Newtonsoft.Json -Force

followed by: 其次是:

Install-Package Newtonsoft.Json -Version <press tab key for autocomplete>

#3楼

I've used Xavier's answer quite a bit. 我已经使用了Xavier的答案了。 I want to add that restricting the package version to a specified range is easy and useful in the latest versions of NuGet. 我想补充说,在最新版本的NuGet中,将软件包版本限制到指定范围非常简单有用。

For example, if you never want Newtonsoft.Json to be updated past version 3.xx in your project, change the corresponding package element in your packages.config file to look like this: 例如,如果您从未希望Newtonsoft.Json在项目中更新超过3.xx版本,请将packages.config文件中的相应package元素更改为如下所示:

<package id="Newtonsoft.Json" version="3.5.8" allowedVersions="[3.0, 4.0)" targetFramework="net40" />

Notice the allowedVersions attribute. 请注意allowedVersions属性。 This will limit the version of that package to versions between 3.0 ( inclusive ) and 4.0 ( exclusive ). 这会将该软件包的版本限制在3.0 )和4.0独占 )之间的版本。 Then, when you do an Update-Package on the whole solution, you don't need to worry about that particular package being updated past version 3.xx . 然后,当您在整个解决方案上执行Update-Package时,您无需担心特定包在版本3.xx更新。

The documentation for this functionality is here . 此功能的文档在此处


#4楼

As of Nuget 2.8 there is a feature to downgrade a package. Nuget 2.8开始,有一个降级软件包的功能。

Nuget 2.8 Release Notes Nuget 2.8发行说明

Example: 例:

The following command entered into the Package Manager Console will downgrade the couchbase client to version 1.3.1.0 输入到Package Manager控制台的以下命令会将couchbase客户端降级到版本1.3.1.0

Update-Package CouchbaseNetClient -Version 1.3.1.0

Result: 结果:

Updating 'CouchbaseNetClient' from version '1.3.3' to '1.3.1.0' in project [project name].
Removing 'CouchbaseNetClient 1.3.3' from [project name].
Successfully removed 'CouchbaseNetClient 1.3.3' from [project name].

Something to note as per crimbo below: 根据下面的crimbo注意事项:

"this approach doesn't work for downgrading from one prerelease version to other prerelease version - it only works for downgrading to a release version" “这种方法不适用于从一个预发布版本降级到其他预发布版本 - 它只适用于降级到发布版本”


#5楼

Now, it's very much simplified in Visual Studio 2015 . 现在,它在Visual Studio 2015中非常简化。 You can do Downgrade / Upgrade within the User interface itself, without executing commands in the Package Manager Console. 您可以在用户界面本身内进行Downgrade / Upgrade ,而无需在程序包管理器控制台中执行命令。

  1. Right click on your project and go to Manage Nuget Packages . Right click on your project然后go to Manage Nuget Packages

  2. Look at the below image. 请看下面的图片。

    • Select your Package and Choose the Version , which you wanted to install. Select your Package and Choose the Version您要安装的版本。

Project的Nuget Package Manager窗口

Very Very Simple, Isn't it? 很简单,不是吗? :) Hope this helps... :) 希望这可以帮助...


#6楼

获得它的另一个更多手动选项:

.nuget\nuget.exe install Newtonsoft.Json -Version 4.0.5
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值