[英]NuSpec-generated NuGet file is resolving the wrong version of a dependency - how can I force it to do otherwise?
I have created a NuSpec file for my .NET Project as follows: 我为我的.NET项目创建了一个NuSpec文件,如下所示:
<?xml version="1.0"?>
<package>
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Author</authors>
<description>My Project</description>
<owners>Me</owners>
<dependencies>
</dependencies>
</metadata>
</package>
My project also has two NuGet provided dependencies, these being: 我的项目还有两个NuGet提供的依赖项,它们是:
<package id="Autofac" version="3.5.2" targetFramework="net451" />
<package id="Autofac.Extras.NLog" version="1.2.3" targetFramework="net451" />
When I create the NuGet package for my project using this NuSpec, NuGet is smart enough to pull these addtional dependencies in. When I install my NuGet package in a new Project, I also get the Autofac
and Autofac.Extras.NLog
dependencies too, referenced and automatically inserted into the packages.config for my new Project. 当我使用这个NuSpec为我的项目创建NuGet包时,NuGet非常聪明,可以将这些附加依赖项纳入其中。当我在新项目中安装我的NuGet包时,我也得到
Autofac
和Autofac.Extras.NLog
依赖项,引用并自动插入到我的新项目的packages.config中。
However... the version of Autofac I get is wrong. 但是......我得到的Autofac版本是错误的。 Rather than version
3.5.2
I get version 2.6.1.841
: 而不是版本
3.5.2
我得到版本2.6.1.841
:
<package id="Autofac" version="2.6.1.841" targetFramework="net451" />
<package id="Autofac.Extras.NLog" version="1.2.3" targetFramework="net451" />
Now, Autofac.Extras.NLog
has a dependency of ≥ 2.2.4.900
(at time of writing). 现在,
Autofac.Extras.NLog
的依赖性≥ 2.2.4.900
(在撰写本文时)。 I have two questions: 我有两个问题:
Autofac.Extras.NLog
Autofac dependency by installing Autofac 2.6.1.841
. Autofac 2.6.1.841
实现Autofac.Extras.NLog
Autofac依赖性。 When it then comes to fulflling my project's Autofac depdency, it is seeing that Autofac is already installed and therefore does nothing. 3.5.2
? 3.5.2
? 2.6.1.841
rather than 2.2.4.900
, which is the minimum version specified in the Autofac.Extras.NLog
dependency? 2.6.1.841
而不是2.2.4.900
,这是Autofac.Extras.NLog
依赖项中指定的最小版本? you can restrict artifact version to be referenced by specifying version number in a pair of square brackets. 您可以通过在一对方括号中指定版本号来限制要引用的工件版本。 please find sample below
请在下面找到示例
<package id="Autofac" version="[3.5.2]" targetFramework="lib/net45" />
edit your packages.config file with the above line , and see if that works ..!! 用上面的代码编辑你的packages.config文件,看看是否有效.. !!
A solution is to add these dependencies to the NuSpec file: 解决方案是将这些依赖项添加到NuSpec文件中:
<?xml version="1.0"?>
<package>
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Author</authors>
<description>My Project</description>
<owners>Me</owners>
<dependencies>
<group targetFramework="net451">
<dependency id="Autofac" version="3.5.2"/> <!-- EXTRA DEPENDENCY -->
</group>
</dependencies>
</metadata>
</package>
It would still be good to know if there's a solution where you don't have to maintain the NuSpec file every time there are dependency version changes in the project you're packaging. 了解是否存在一个解决方案仍然是一件好事,在每次在打包的项目中存在依赖项版本更改时,您不必维护NuSpec文件。
Looks like Nuget 3.5 (now in Beta) finally solved this issue. 看起来像Nuget 3.5(现在在Beta中)终于解决了这个问题。 I tested on my project and the dependencies were calculated correctly (Nuget 3.4 didn't calculate them correctly).
我测试了我的项目并正确计算了依赖项(Nuget 3.4没有正确计算它们)。
This is the pull request: https://github.com/NuGet/NuGet.Client/pull/632/files 这是拉取请求: https : //github.com/NuGet/NuGet.Client/pull/632/files
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.