393

我想安装旧版本的包 ( Newtonsoft.Json)。但 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'.

我该怎么做?

4

5 回答 5

584

尝试以下操作:

Uninstall-Package Newtonsoft.Json -Force

其次是:

Install-Package Newtonsoft.Json -Version <press tab key for autocomplete>
于 2012-04-18T15:25:04.023 回答
268

NuGet 2.8开始,有一个降级包的功能。

NuGet 2.8 发行说明

例子:

输入包管理器控制台的以下命令会将 Couchbase 客户端降级到版本 1.3.1.0。

Update-Package CouchbaseNetClient -Version 1.3.1.0

结果:

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].

根据下面的 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

于 2014-02-12T23:09:13.090 回答
51

我已经多次使用Xavier 的答案。我想补充一点,在最新版本的 NuGet 中,将包版本限制在指定范围内既简单又有用。

例如,如果您不想在项目Newtonsoft.Json中更新过去的版本3.x.x,请将文件中的相应package元素更改packages.config为如下所示:

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

注意allowedVersions属性。这会将该软件包的版本限制为3.0( inclusive ) 和4.0( Exclusive ) 之间的版本。然后,当您执行Update-Package整个解决方案时,您无需担心该特定包被更新为过去版本3.x.x

此功能的文档在此处

于 2013-06-25T14:18:54.427 回答
21

Now, it's very much simplified in Visual Studio 2015 and later. You can do downgrade / upgrade within the User interface itself, without executing commands in the Package Manager Console.

  1. Right click on your project and *go to Manage NuGet Packages.

  2. Look at the below image.

    • Select your Package and Choose the Version, which you wanted to install.

NuGet Package Manager window of Project

Very very simple, isn't it? :)

于 2016-10-27T10:18:03.073 回答
1

Another more manual option to get it:

.nuget\nuget.exe install Newtonsoft.Json -Version 4.0.5
于 2019-08-31T07:01:26.993 回答