简体   繁体   English

阻止Nuget下载依赖项的最新版本

[英]Prevent Nuget from downloading the most updated version of a dependency

I used Nuget for downloading a specific version of CouchbaseClient which is a .Net client for a NoSql product. 我使用Nuget下载特定版本的CouchbaseClient ,这是NoSql产品的.Net客户端。

This dll has a dependency in Newton.Json , so this is what happened when using Nuget: 该dll在Newton.Json中具有依赖项,因此使用Nuget时会发生以下情况:

Install-Package CouchbaseNetClient -Version 1.3.6
Attempting to resolve dependency 'Newtonsoft.Json'.
Installing 'Newtonsoft.Json 6.0.5'.
Successfully installed 'Newtonsoft.Json 6.0.5'.
Installing 'CouchbaseNetClient 1.3.6'.
Successfully installed 'CouchbaseNetClient 1.3.6'.
Adding 'Newtonsoft.Json 6.0.5' to DataAccess.
Successfully added 'Newtonsoft.Json 6.0.5' to DataAccess.
Adding 'CouchbaseNetClient 1.3.6' to DataAccess.
Successfully added 'CouchbaseNetClient 1.3.6' to DataAccess.

The problem is, that when i ran the unit tests an exception was thrown that it is looking for Newton.Json version 4.5.0. 问题是,当我运行单元测试时,抛出了一个异常,它正在寻找Newton.Json版本4.5.0。

So , i needed to remove manually the Newton.Json 6.0.5 that Nuget downloaded for me and added with Nuget Newton.Json 4.5.0. 因此,我需要手动删除Nuget为我下载并添加了Nuget Newton.Json 4.5.0的Newton.Json 6.0.5。

Is there a simpler way to do it? 有更简单的方法吗? I do not want to do this manual process each time i will download a package with dependencies which are not the most updated version. 我不想每次我下载具有非最新版本依赖关系的软件包时都执行此手动过程。

Your options are: 您的选择是:

  1. Add a binding redirect for Newtonsoft.Json in your app.config so 4.5 is redirected to 6.0.5. 在您的app.config中为Newtonsoft.Json添加绑定重定向,以便将4.5重定向到6.0.5。
  2. Add a constraint to your packages.config to restrict the Newtonsoft.Json package version. 在您的packages.config中添加一个约束以限制Newtonsoft.Json软件包的版本。
  3. Install a more recent NuGet version (2.5 or above). 安装较新的NuGet版本(2.5或更高版本)。
  4. Use the -DependencyVersion parameter to change the default behaviour of Install-Package. 使用-DependencyVersion参数可以更改Install-Package的默认行为。
  5. Create a project template with your required NuGet packages and re-use that. 使用所需的NuGet包创建项目模板,然后重复使用。

If Newtonsoft.Json 4.5.11 was already installed then CouchbaseNetClient would not install a later version unless you do not have Newtonsoft.Json installed already or you are using an old version of NuGet (older than NuGet 2.5). 如果已经安装了Newtonsoft.Json 4.5.11,则除非尚未安装Newtonsoft.Json或使用的是NuGet的旧版本(比NuGet 2.5的旧版本)大,否则CouchbaseNetClient不会安装更高的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM