简体   繁体   English

NuSpec生成的NuGet文件正在解析依赖项的错误版本 - 如何强制它执行其他操作?

[英]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包时,我也得到AutofacAutofac.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: 我有两个问题:

  • It looks as though NuGet is first fulfilling the Autofac.Extras.NLog Autofac dependency by installing Autofac 2.6.1.841 . 看起来NuGet首先通过安装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. 然后,当它实现我的项目的Autofac depdency时,它看到已经安装了Autofac,因此什么也没做。 How can I make NuGet resolve the Autofac dependency to version 3.5.2 ? 如何让NuGet将Autofac依赖解析为版本3.5.2
  • Even though NuGet is resolving the 'wrong' NuGet depdendency (at least for my purposes), why is it resolving to 2.6.1.841 rather than 2.2.4.900 , which is the minimum version specified in the Autofac.Extras.NLog dependency? 即使NuGet正在解决'错误的'NuGet depdendency(至少对我而言),为什么它会解析为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没有正确计算它们)。

Nuget download page Nuget下载页面

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.

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