简体   繁体   English

.NET程序集依赖项

[英].NET Assembly Dependencies

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) 我已经构建了一个可重用的通用C#类库项目说(A.dll)引用其他3个程序集说(B.dll,C.dll和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. 但是,如果我想在另一个项目中重用我的组件A.dll,我仍然需要包含对B.dll,C.dll和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? 有没有什么办法可以配置A.dll来构建它的所有依赖项到A.dll所以我不必包含其他3个程序集?

Cheers 干杯

It's possible to merge assemblies, using the tool ILMerge : 可以使用ILMerge工具合并程序集:

C:\Program Files\Microsoft\ILMerge\ILMerge.exe /target:library /out:abcd.dll a.dll b.dll c.dll d.dll"

This will merge the dlls a , b , c and d into abcd.dll . 这将合并的dll abcdabcd.dll It will also merge the debugging symbols but not the XML documentation. 它还将合并调试符号,但不合并XML文档。

Also you'll have to reference the dll itself in new projects and not the respective projects. 此外,您必须在新项目中引用dll本身,而不是相应的项目。 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. Mono项目也有一个工具,称为mkbundle。

Also available is ILRepack , which aims to be compatible with ILMerge, but is FLOSS. 还有ILRepack ,它旨在与ILMerge兼容,但是FLOSS。

This would be something like static linking of DLLs which works fine with native C++. 这类似于DLL的静态链接,可以与原生C ++一起使用。 As far as I know you cannot statically link assemblies in .NET code, thus you have to include all DLLs. 据我所知,你不能静态链接.NET代码中的程序集,因此你必须包括所有的DLL。

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

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