.NET Assembly Dependencies

冷暖自知 提交于 2020-01-01 05:27:20

问题


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


回答1:


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"

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.

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.




回答2:


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.



来源:https://stackoverflow.com/questions/2265330/net-assembly-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!