创建具有多个 DLL 的 nuget 包 [英] Create nuget package with multiple DLLs

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

问题描述

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

我的图书馆我的图书馆.sln我的图书馆.CoreMyLibrary.Core.csprojMyLibrary.ExtensionsMyLibrary.Extensions.csprojMyLibrary.TestsMyLibrary.Tests.csproj

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

TLDR:创建具有多个项目/程序集的 NuGet 包的最佳做法是什么?有没有专门针对这个的教程?我发现的教程都侧重于简单的单项目演示.

解决方案

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

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

<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"><元数据>...</元数据><文件><file src="binReleaseMyLibrary.Extensions.dll" target="lib
et40"/><file src="binReleaseMyLibrary.Tests.dll" target="lib
et40"/></文件></包>

通过此设置,您的所有引用最终都应位于 NuGet 包中的适当位置.你仍然有硬编码的发布",但我敢打赌,无论如何都不会分发他们的调试版本的 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="binReleaseMyLibrary.Extensions.dll" target="lib
et40" />
    <file src="binReleaseMyLibrary.Tests.dll" target="lib
et40" />
  </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天全站免登陆