如何将dll合并为一个dll

时间:2015-03-08 21:24:55

标签: c# dll

在visual studio 2012中使用c#,我创建了一个类库FileTube.dll 它使用其他3个dll。 我想制作一个单独的dll来包含那些因此我可以通过nuget发布我的库。 我尝试了3种方法都失败了:

接近1:在vistual studio中,我将“Embed Interop Assembly”设置为true,我收到此错误:

Error   2   Cannot embed interop types from assembly 'DiffieHellman.dll' because it is missing the 'GuidAttribute' attribute    DiffieHellman.dll

方法2:我使用了ILMergeGUI。它生成了用于ILMerge的代码,该代码因错误而失败: 你调用的对象是空的。 这是命令:

"C:\Program Files (x86)\Microsoft\ILMerge\ILMerge.exe"
/ndebug
/copyattrs
/targetplatform:4.0,"C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
/out:"C:\temp\z.dll"
"C:\\FileTube\TestApp\bin\Debug\FileTube.dll"
"C:\\FileTube\TestApp\bin\Debug\DiffieHellman.dll"
"C:\\FileTube\TestApp\bin\Debug\Org.Mentalis.Security.dll"
"C:\\FileTube\TestApp\bin\Debug\Tamir.SharpSSH.dll"

接近3: 我跟着这个tutorial 使用反射来包含dll程序集。区别在于教程有一个主要的可执行文件,并且在我尝试在我的dll中包含dll时在可执行文件中包含dll。所以我将反射代码添加到我的主dll的类构造函数中。它编译但如果我重命名外部dll意味着它没有真正加载它会失败。

有什么想法吗?

1 个答案:

答案 0 :(得分:4)

您有几种选择:

OR

  • 使用SmartAssembly(商业)之类的工具 它可以嵌入和合并其他东西(无需更改源代码)

OR

  • code that yourself in less than 10 lines(免费但最少的源代码更改)
    将所有需要的依赖项标记为"嵌入式资源" - 这样它们就包含在EXE文件中......您需要设置一个AssemblyResolve处理程序,它在运行时从Resources读取并将所需的DLL返回给.NET运行时...

(答案复制自:How to merge multiple assemblies into one?

相关问题