我目前正在尝试为 this solution 中的所有项目发布大量 nuget 包。 .这些项目设置在一个简单的树中,Myre 是基础项目,一切都依赖于它:
Myre <- Myre.Debugging <- Myre.Debugging.UI <- Myre.UI
Myre <- Myre.UI
Myre <- Myre.Entities <- Myre.Graphics
我正在尝试将每个单独的项目打包为一个 nuget 包,并根据需要对其他 Myre 子项目包具有正确的依赖关系。
我的第一步是为 Myre 制作一个包( nuspec 和 bat file of process )。这似乎工作得很好,图库显示 Myre 具有 ninject(另一个 nuget 包)依赖项,并且一切正常。
当我尝试制作下一个包装时,问题就出现了。 Myre.Debugging取决于 Myre(具有正常的项目引用),仅此而已。使用 this nuspec使用 nuget 包(详细)给出:
Attempting to build package from '(x86) Myre.Debugging.csproj'.
Packing files from 'C:\Long_Path\Myre\Myre.Debugging\bin\x86\Release'.
Add file 'C:\Long_Path\Myre\Myre.Debugging\bin\x86\Release\Myre.Debugging.dll' to package as 'lib\net40-Client\Myre.Debugging.dll'
Add file 'C:\Long_Path\Myre\Myre\bin\x86\Release\Myre.dll' to package as 'lib\net40-Client\Myre.dll'
Add file 'C:\Long_Path\Myre\Myre\bin\x86\Release\Myre.XML' to package as 'lib\net40-Client\Myre.XML'
Found packages.config. Using packages listed as dependencies
Id: Myre.Debugging
Version: 1.0.0.2
Authors: Microsoft
Description: Description
Dependencies: Ninject (= 3.0.1.10)
Added file 'lib\net40-Client\Myre.Debugging.dll'.
Added file 'lib\net40-Client\Myre.dll'.
Added file 'lib\net40-Client\Myre.XML'.
Successfully created package 'C:\Long_Path\Myre\Myre.Debugging\Myre.Debugging.1.0.0.2.nupkg'.
如您所见,它获取了一个 packages.config 文件(大概来自 Myre,因为没有 here ),然后它从中确定 Ninject 依赖项。如果我希望 Myre.Debugging 和 Myre 成为一个包,那就没问题了。然而,这不是我想要的,我希望 Myre.Debugging 获得对 Myre 包的依赖。
如何设置 nuget 以使用 Myre 作为包引用,而不是简单地将 Myre 程序集复制到 Myre.Debugging 包中?
编辑::我尝试不使用 -IncludeReferencedProjects 并指定:
<dependencies>
<dependency id="Myre" version="1.0.0.1" />
</dependencies>
但出于某种原因,这只是创建了一个完全没有依赖关系的包!即使像这样手动指定依赖项确实有效,也不是很理想。
最佳答案
根据NuGet command line reference for the Pack command , IncludeReferencedProjects
开关的工作原理如下:
Include referenced projects either as dependencies or as part of the package. If a referenced project has a corresponding nuspec file that has the same name as the project, then that referenced project is added as a dependency. Otherwise, the referenced project is added as part of the package.
在您的情况下,Myre.Debugging.nuspec与项目文件名不匹配:(x86) Myre.Debugging.csproj等。我怀疑您需要匹配这些文件名才能使该命令行选项起作用。
或者,如果您想让它与
<dependencies>
一起使用nuspec 文件中的元素,您可能会面临名称不匹配问题的另一个变体。您的 Myre.nuspec文件定义其 ID 如下:<id>$id$</id>
NuSpec reference说
$id$
token 被替换为“程序集名称”。如果说的是 DLL 的名称(忽略扩展名),那么我认为生成的 ID 将是 (x86) Myre
等。您可能想暂时尝试对 ID 进行硬编码,以查看是否能解决问题。我还没有尝试进行这些建议的更改,我不能保证它们会起作用,但我希望这为您指明了正确的方向。祝你好运!
关于deployment - 创建多个 Nuspec 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20079651/