使用多个 DLL 创建 nuget 包 [英] Create nuget package with multiple DLLs

查看:107
本文介绍了使用多个 DLL 创建 nuget 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个具有这种结构的项目:

MyLibrary\我的图书馆MyLibrary.Core\MyLibrary.Core.csprojMyLibrary.Extensions\MyLibrary.Extensions.csprojMyLibrary.Tests\MyLibrary.Tests.csproj

我想创建一个单独的 NuGet 包,其中包含 MyLibrary.Core.dll 和 MyLibrary.Extensions.dll.我似乎无法弄清楚如何让 NuGet 做到这一点.我尝试手动构建规范文件,并尝试使用nuget spec MyLibrary.Core.csproj"构建一个.我已经尝试将所有 DLL 添加到 lib/文件夹中,我认为这是将 DLL 添加到包的基于约定的机制.在每种情况下,我都可以将 MyLibary.Core.dll 放入包中,但 MyLibrary.Extensions.dll 最终不会与它一起打包.

TLDR:创建具有多个项目/程序集的 NuGet 包的最佳实践是什么?有没有专门针对这个的教程?我发现的教程都集中在简单的单项目演示上.

解决方案

您将在单个项目(或 nuspec 文件)上运行 NuGet,但它支持通过 file 元素.此元素使用项目引用的名称,因此您无需 a) 查找其他项目文件的位置,以及 b) 将文件复制到特定位置作为构建后步骤.

假设您有一个 MyLibrary.Core.csproj 的 nuspec 文件,并且它引用了 MyLibrary.ExtensionsMyLibrary.Tests,这样它们构建后最终在 bin 目录中:

<元数据>...</元数据><文件><file src="bin\Release\MyLibrary.Extensions.dll" target="lib\net40"/><file src="bin\Release\MyLibrary.Tests.dll" target="lib\net40"/></文件></包>

通过此设置,您的所有引用都应位于 NuGet 包中的适当位置.那里仍然有硬编码的Release",但我打赌很可能不会分发他们的调试版本的 NuGet 包.

Let's say I have a project with this structure:

MyLibrary\
  MyLibrary.sln
  MyLibrary.Core\
    MyLibrary.Core.csproj
  MyLibrary.Extensions\
    MyLibrary.Extensions.csproj
  MyLibrary.Tests\
    MyLibrary.Tests.csproj

I want to create a single NuGet package which packages MyLibrary.Core.dll and MyLibrary.Extensions.dll. I can't seem to figure out how to get NuGet to do this. I've tried building a spec file manually and I've tried building one using "nuget spec MyLibrary.Core.csproj". I've tried adding all of the DLLs to a lib/ folder which I understand to be the convention-based mechanism for adding DLLs to the package. In every case I can get the MyLibary.Core.dll to get into the package but the MyLibrary.Extensions.dll does not end up packaged along with it.

TLDR: What is the best practice for creating a NuGet package with multiple projects / assemblies? Is there a tutorial out there that focuses on this? The tutorials I've found all focus on simple single-project demos.

解决方案

You'll run NuGet on a single project (or nuspec file), but it supports pointers to other projects via the file element. This element uses the names of your project's References, so you avoid having to a) find the location of other project files, and b) copy files to a particular place as a post-build step.

Supposing you have a nuspec file for MyLibrary.Core.csproj, and it references MyLibrary.Extensions and MyLibrary.Tests such that they end up in the bin directory after a build:

<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    ...
  </metadata>
  <files>
    <file src="bin\Release\MyLibrary.Extensions.dll" target="lib\net40" />
    <file src="bin\Release\MyLibrary.Tests.dll" target="lib\net40" />
  </files>
</package>

With this setup, all of your references should end up in the appropriate place in the NuGet package. You still have the hard-coded 'Release' in there, but I'd wager most probably don't distribute NuGet packages of their debug builds anyway.

这篇关于使用多个 DLL 创建 nuget 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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