简体   繁体   English

发布 .net 标准库及其所有依赖项?

[英]Publish .net standard library with all it's dependencies?

I have created a system which loads dynamically a library and executes it's main class.我创建了一个动态加载库并执行它的主类的系统。 Everything works perfect, the problem I have is how to publish this DLL with all it's dependencies.一切正常,我遇到的问题是如何发布此 DLL 及其所有依赖项。 As no executable project is referencing it I have to manually retrieve the dependencies: try to load the library, check the needed DLL's, go to the NuGet cache folder, copy the libraries, try again, check if it complains about more dependencies and so on until it has all the required libraries.由于没有可执行项目引用它,我必须手动检索依赖项:尝试加载库,检查所需的 DLL,转到 NuGet 缓存文件夹,复制库,​​再试一次,检查它是否抱怨更多依赖项等等直到它拥有所有必需的库。

This is a true pain and I haven't found any information on how to do this, is it possible or am I stuck with this?这是一个真正的痛苦,我还没有找到任何关于如何做到这一点的信息,有可能还是我坚持这个?

The library is a .net standard 2.0 library, I did this before with .net classic and the output folder always contained all the required libraries even the ones comming from a NuGet package, but with .net standard something has changed and now only libraries from referenced projects are being copied, no referenced NuGet package is being copied to the output folder.该库是一个 .net 标准 2.0 库,我之前使用 .net classic 这样做过,输出文件夹始终包含所有必需的库,即使是来自 NuGet 包的库,但使用 .net 标准,有些东西已经改变,现在只有来自正在复制引用的项目,没有将引用的 NuGet 包复制到输出文件夹。

Cheers.干杯。

At the time of writing, it looks like it's by design and there's quite some fuss and confusion about it, see logged issue on GitHub .在撰写本文时,它看起来像是设计使然,并且有很多关于它的大惊小怪和混淆,请参阅GitHub 上记录的问题

Moreover, when publishing a NuGet package for project A referencing project B,此外,在为引用项目 B 的项目 A 发布 NuGet 包时,
B becomes a NuGet dependency in A; B 成为 A 中的 NuGet 依赖项; B's assemby is not included in A's NuGet package. B 的程序集不包含在 A 的 NuGet 包中。

I deal with it by publishing my own NuGet packages.我通过发布我自己的 NuGet 包来处理它。

I only don't like it to have a NuGet package for project B if that one is only relevant to be used with/by project A, as it will appear seperately in my NuGet feed.我只是不喜欢为项目 B 提供 NuGet 包,如果该包仅与项目 A 一起使用/由项目 A 使用,因为它将单独出现在我的 NuGet 提要中。

Try:尝试:

dotnet publish

All the dependent libraries should be copied to the publish output folder.所有依赖库都应复制到发布输出文件夹。

Here is a practical, painless solution to publishing DLLs:这是发布 DLL 的实用且轻松的解决方案:

So, having fought with this for a bit, I came up with a more elegant solution.因此,经过一段时间的斗争,我想出了一个更优雅的解决方案。 I tested this approach and deployed a full build with a plugin with many external dependencies to Ubuntu 18.04 and it ran perfectly.我测试了这种方法,并部署了一个带有许多外部依赖项的插件的完整构建到 Ubuntu 18.04,它运行完美。

Create a new project of type Console Application instead of Class Library.创建一个类型为 Console Application 而不是类库的新项目。 Put all your library code files into the Console Application and add the dependencies.将所有库代码文件放入控制台应用程序并添加依赖项。 Get rid of the Class Library project (you don't need it anymore).摆脱类库项目(您不再需要它)。 Finally, publish the Console Application.最后,发布控制台应用程序。 You will get a DLL with all of the dependencies.您将获得一个包含所有依赖项的 DLL。 You can use this DLL like any other DLL.您可以像使用任何其他 DLL 一样使用此 DLL。

I suggest naming the console app project with "Library" on the end of it and adding a README just to document its not really an application even though the project is configured to build as one.我建议将控制台应用程序项目命名为“Library”,并添加一个 README 来记录它并不是真正的应用程序,即使该项目被配置为构建为一个应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM