.NET 程序集依赖项
也许我在这里遗漏了一些明显的东西,但是...
我已经构建了一个可重用的通用 C# 类库项目(A.dll),它引用了 3 个其他程序集(B.dll、C.dll 和 D.dll)
但是如果我想要要在另一个项目中重用我的组件 A.dll,我仍然必须包含对 B.dll、C.dll 和 D.dll 的引用。
有什么方法可以配置 A.dll 将其所有依赖项构建到 A.dll 中,这样我就不必包含其他 3 个程序集?
干杯
Perhaps I am missing something obvious here but...
I have built a reusable generic C# class library project say (A.dll) which references 3 other assemblies say (B.dll, C.dll and D.dll)
However if I want to reuse my component A.dll in another project I still have to include the references to B.dll, C.dll and D.dll.
Is there any way you can configure A.dll to build all its dependencies into the A.dll so I don't have to include the other 3 assemblies?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以使用工具 ILMerge:
这会将 dll
a
、b
、c
和d
合并到abcd.dll
。它还会合并调试符号,但不会合并 XML 文档。此外,您还必须在新项目中引用 dll 本身,而不是相应的项目。一个例外是,如果您将库合并到可执行文件中,在这种情况下,您可以引用相应的库/项目,因为它们将与可执行文件一起加载。
Mono 项目也有一个用于此目的的工具,称为 mkbundle。
还可以使用 ILRepack,它旨在与 ILMerge 兼容,但属于 FLOSS。
It's possible to merge assemblies, using the tool ILMerge:
This will merge the dlls
a
,b
,c
andd
intoabcd.dll
. It will also merge the debugging symbols but not the XML documentation.Also you'll have to reference the dll itself in new projects and not the respective projects. An exception to this is if you merge libraries into an executable, in that case you can reference the respective libraries/projects because they will be loaded with the executable.
The Mono Project also has a tool for this, called mkbundle.
Also available is ILRepack, which aims to be compatible with ILMerge, but is FLOSS.
这就像 DLL 的静态链接一样,可以与本机 C++ 配合良好。据我所知,您无法在 .NET 代码中静态链接程序集,因此您必须包含所有 DLL。
This would be something like static linking of DLLs which works fine with native C++. As far as I know you cannot statically link assemblies in .NET code, thus you have to include all DLLs.