自动构建NuGet程序包,包括引用的依赖项 [英] Build NuGet Package automatically including referenced dependencies

查看:580
本文介绍了自动构建NuGet程序包,包括引用的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要运行本地/内部NuGet存储库.我想我已经想出了如何通过使用NuGet将其包含在虚拟项目中并将其扫描到

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...

特别是:

  1. 创建解决方案
  2. 添加新项目
  3. 添加对各种.dll文件/其他项目的引用<-这是缺少的部分
  4. 通过程序包管理器/cmdline/任何方式添加NuGet程序包
  5. 某物自动创建.nupkg
  1. Create a solution
  2. Add a new Project
  3. Add references to various .dll files/other projects <-- this is the missing part
  4. Add NuGet packages via package manager / cmdline / whatever
  5. something automatically creates the .nupkg

根据我发现的情况,您应该做类似的事情

From what I've found, you're supposed to do things like

  • 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:

  • 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).nuget\NuGet.exe" pack "$(ProjectPath)" -Properties Configuration=Release
move /Y *.nupkg "$(TargetDir)"

我将解决一些会自动从项目引用中创建.nuspec清单的问题.然后从理论上讲,可以将+ nuget构建事件汇总到一个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.

编号(2)从 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆