.NET程序集的依赖程序、NET

2023-09-03 13:05:39 作者:爱刺痛命脉

也许我缺少明显的东西在这里,但...

Perhaps I am missing something obvious here but...

我建立了一个可重复使用的通用的C#类库项目说(A.DLL),它引用了其他3个总成说(B.DLL,C.dll和D.dll)

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)

但是,如果我想重用我的组件A.DLL在另一个项目中,我还是要包括引用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打造其所有的依赖到A.DLL所以我没有包括其他3个总成?

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?

干杯

推荐答案

这是可能的合并组件,使用工具 ILMerge :

It's possible to merge assemblies, using the tool ILMerge:

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

这将合并的dll A B C D abcd.dll 。它也将合并调试符号而不是XML文档。

This will merge the dlls a, b, c and d into abcd.dll. It will also merge the debugging symbols but not the XML documentation.

另外,你必须引用DLL本身在新的项目,而不是各自的项目。如果合并库成可执行的例外是,你可以在这种情况下,引用的各个库/项目,因为它们将被装入可执行文件。

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.

Mono项目也有这样的工具,叫做mkbundle。

The Mono Project also has a tool for this, called mkbundle.

此外,还提供 ILRepack 的,其目的是与ILMerge兼容,但FLOSS。

Also available is ILRepack, which aims to be compatible with ILMerge, but is FLOSS.