自动构建 NuGet 包,包括引用的依赖项 [英] Build NuGet Package automatically including referenced dependencies
问题描述
我想运行本地/内部NuGet 存储库.我想我已经想出了如何重用"现有的 NuGet 包,方法是使用 NuGet 将它们包含在一个虚拟项目中并将包文件扫描到 抓取我本地缓存的 .nupkg
文件,但是...
I want to run a local/internal NuGet repository. I think I've figured out how to "reuse" existing NuGet packages by including them in a dummy project using NuGet and scanning the package file to grab my locally-cached .nupkg
files, but...
具体来说:
- 创建解决方案
- 添加新项目
- 添加对各种
.dll
文件/其他项目的引用<--这是缺少的部分 - 通过包管理器/cmdline/whatever 添加 NuGet 包
- something 自动创建
.nupkg
- Create a solution
- Add a new Project
- Add references to various
.dll
files/other projects <-- this is the missing part - Add NuGet packages via package manager / cmdline / whatever
- something automatically creates the
.nupkg
根据我的发现,你应该这样做
From what I've found, you're supposed to do things like
- 手动编辑您的
.csproj
文件以添加<BuildPackage>true</BuildPackage>
以包含依赖项 - 手动创建
.nuspec
文件并手动 列出你的依赖项(类似的?) - 在您的
.nuspec
文件上手动运行nuget pack
- manually edit your
.csproj
file to add<BuildPackage>true</BuildPackage>
to include dependencies - manually create a
.nuspec
file and manually list your dependencies (similar ?) - manually run
nuget pack
on your.nuspec
file
但一切都是手动的,这很愚蠢.即使是半自动的解决方案仍然很笨拙或半手动:
But everything is manual, which is stupid. Even the semi-automatic solutions are still awkward or half-manual:
- 创建
.nuspec
模板 - 似乎不包含依赖项,只是元数据 nuget 包通过构建事件(第 5 步),您需要手动将其添加到每个项目中,并且它具有 它自己的怪癖:
- Create
.nuspec
templates - doesn't seem to include dependencies, just metadata nuget pack via build-event (step #5), which you need to add manually to every project, and it has its own quirks:
"$(SolutionDir).nugetNuGet.exe" pack "$(ProjectPath)" -Properties Configuration=Release
move /Y *.nupkg "$(TargetDir)"
我将满足于从项目引用中自动创建 .nuspec
清单的东西.然后理论上 + nuget build-event 可以汇总到 build-project/nuget 包中,这是我真正想看到的.
I'll settle for something that automatically creates a .nuspec
manifest from project references. Then theoretically that + the nuget build-event can be rolled up into a build-project/nuget package, which is what I really want to see.
推荐答案
你的观点 #3 (添加对各种 .dll 文件/其他项目的引用 <-- 这是缺少的部分)包含两个不同的问题:(1) 添加对各种 dll 文件的引用,以及 (2) 在同一解决方案中添加对其他项目的引用.
Your point #3 (Add references to various .dll files/other projects <-- this is the missing part) really contains two different issues: (1) add references to various dll files, and (2) add references to other projects in the same solution.
从 NuGet 2.5.在为项目创建 NuGet 包时,您可以添加一个选项以在同一解决方案中包含对其他项目的引用:
Number (2) here has gotten some added support as of NuGet 2.5. You can add an option to include references to other projects in the same solution when creating a NuGet package for a project:
nuget pack projectfile.csproj -IncludeReferencedProjects
如果 projectfile.csproj
引用解决方案中也公开为 NuGet 包的任何其他项目,则这些项目的 NuGet 包将作为依赖项添加.如果它在您的解决方案中引用了不将自身公开为 NuGet 包的项目,则它们的 dll 将包含在此 NuGet 包中.
If projectfile.csproj
references any other projects in your solution that also is exposed as NuGet packages, these projects' NuGet packages will be added as dependencies. If it references projects in your solution that doesn't expose themselves as NuGet packages, their dlls will be included in this NuGet package.
至于 (1),如果您发现自己经常向项目中添加不能作为 NuGet 包使用的 dll,您可以使用这些文件创建自己的(内部)NuGet 包.如果您随后将这些 dll 作为 NuGet 包而不是直接添加文件,则此 NuGet 包将成为您项目的 NuGet 包中的依赖项.
As for (1), if you find yourself often adding dlls to your projects that aren't available as NuGet packages, you could just create your own (internal) NuGet packages with these files. If you then add these dlls as a NuGet package instead of the files directly, this NuGet package will be a dependency in your project's NuGet package.
这篇关于自动构建 NuGet 包,包括引用的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!