简体   繁体   English

Nuget packages.config和特定版本

[英]Nuget packages.config and specific version

I am trying to create a Nuget package from my project following this guide http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package 我正在尝试按照本指南http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package从我的项目中创建一个Nuget包

I have successfully created a nuspec and nupkg. 我已经成功创建了一个nuspec和nupkg。 My project contains a dependency to Json.NET which I installed via Nuget. 我的项目包含我通过Nuget安装的Json.NET依赖项。 However, I want to specify a specific version of Json.NET to use, version 4.0.7. 但是,我想指定要使用的特定版本的Json.NET,版本4.0.7。 I added the below to my nuspec: 我将以下内容添加到我的nuspec中:

<dependencies>
  <dependency id="Newtonsoft.Json" version="[4.0.7]" />
</dependencies>

When I run nuget pack it seems to detect I have a packages.config 当我运行nuget pack它似乎检测到我有一个packages.config

Using 'MyProject.nuspec' for metadata.
Found packages.config. Using packages listed as dependencies.

This seems to completely ignore my defined dependency in the nuspec as installing the Nuget package lists the dependencies as >= 4.0.7 which pulls in the latest version 4.0.8. 这似乎完全忽略了我在nuspec中定义的依赖关系,因为安装Nuget包将依赖关系列为> = 4.0.7,它引入了最新版本4.0.8。

How can I stop this or preferably keep Nuget pulling in dependencies from the packages.config but allow me to overwrite specific dependencies? 我怎么能阻止这个或者最好让Nuget从packages.config中获取依赖关系,但允许我覆盖特定的依赖项?

I hit the same issue. 我遇到了同样的问题。 You need to define an exact version like this 您需要定义这样的确切版本

<dependencies>
<dependency id="Newtonsoft.Json" version="[4.0.7,4.0.7]" />
</dependencies>

So that will ensure when the project pulls in the dependencies it will be = 4.0.7 not >= 4.0.7 因此,这将确保当项目拉入依赖项时,它将是= 4.0.7而不是> = 4.0.7

The way you specified your version is correct; 你指定版本的方式是正确的; as shown in our versioning docs , [1.0] means 'version == 1.0'. 如我们的版本控制文档中所示,[1.0]表示'version == 1.0'。 The behavior you're describing would be a bug, but I couldn't reproduce the bug. 您描述的行为将是一个错误,但我无法重现该错误。 What I did: 我做了什么:

  • Created a class library 创建了一个类库
  • Added Json.NET via NuGet (it installed 4.0.8) 通过NuGet添加了Json.NET(它安装了4.0.8)
  • Exec'd nuget spec 执行nuget spec
  • Added <dependencies><dependency id="Newtonsoft.Json" version="[4.0.7]" /> to the .nuspec <dependencies><dependency id="Newtonsoft.Json" version="[4.0.7]" />到.nuspec
  • Exec'd nuget pack 执行nuget pack
  • Opened the package in Package Explorer; 在Package Explorer中打开包; it shows the dependency as '= 4.0.7' 它将依赖关系显示为'= 4.0.7'
  • Installed my package in a new project; 在新项目中安装我的包; it shows the dependency as '= 4.0.7' and installs 4.0.7 它将依赖关系显示为'= 4.0.7'并安装4.0.7

屏幕截图截屏2

Perhaps you aren't using the latest version of nuget.exe or the NuGet Visual Studio extension? 也许您没有使用最新版本的nuget.exe或NuGet Visual Studio扩展? When you say it "lists the dependency", where are you seeing that? 当你说它“列出依赖”时,你在哪里看到它? When your package is installed, in Package Explorer, or somewhere else? 安装软件包时,在Package Explorer中还是其他地方?

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

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