参考非 NuGet 引用创建 NuGet 包

编程入门 行业动态 更新时间:2024-10-28 14:32:24
本文介绍了参考非 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 包

本文发布于:2023-11-08 13:10:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569470.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NuGet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!