参考非 NuGet 引用创建 NuGet 包 [英] Creating NuGet package with reference to a non-NuGet reference

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

问题描述

我正在创建一个将 2 个 dll 构建到 NuGet 包中的类库.它有一些对当前没有可引用的 NuGet 包的 dll 的引用.

I am creating a Class Library that builds 2 dlls into a NuGet package. It has a few references to dlls that currently do not have a NuGet package to be referenced from.

我应该如何使我的 NuGet 包依赖于当前通过 NuGet 不可用的那些 dll?

How should I make my NuGet package dependent on those dlls that are currently unavailable via NuGet?

如果我也将它们捆绑在一起,如果一个已经引用这些 dll 的项目拉下我的 NuGet 包,该引用会发生什么情况?

If I bundle them up as well, what happens if a project that already has a reference to these dlls, pulls down my NuGet package, what happens to that reference?

我是否应该为每个 dll 引用创建一个 NuGet 包并使我的 NuGet 包依赖于这些?

Should I just create a NuGet package for each dll reference and make my NuGet package dependent on these?

推荐答案

您可以将 DLL 捆绑到您的 NuGet 包中,而不会产生不良影响.在某些 /libs(或其他)文件夹中已经有这些 DLL 的项目将继续从那里引用它们.NuGet 包中的程序集将引用被拉入 /packages 的捆绑 DLL.

You can bundle the DLLs into your NuGet package with no ill effects. A project that already has those DLLs in some /libs (or whatever) folder will continue to reference them from there. Assemblies in your NuGet package will reference the bundled DLLs that are pulled into /packages.

在您的 nuspec 文件中,使用 元素来包含内部 DLL,如下所示:

In your nuspec file, use the <file> element to include the internal DLLs, as such:

<package>
  <metadata>
    ...
  </metadata>
  <files>
   <file src="PATH_TO_BIN\DependencyOne.dll" target="mylibs" />
   <file src="PATH_TO_BIN\DependencyTwo.dll" target="mylibs" />
  </files>
</packages>

这将在拉取 NuGet 包时产生以下文件结构:

This will result in the following file structure when the NuGet package is pulled:

PATH_TO_PROJECT/packages/YOUR_NUGET_PACKAGE/mylibs/DependencyOne.dll
PATH_TO_PROJECT/packages/YOUR_NUGET_PACKAGE/mylibs/DependencyTwo.dll

target 属性可以指定相对于包根目录的任意路径.

The target attribute can specify any arbitrary path relative to your package root.

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

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