在 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,它会失败,这意味着它并没有真正加载它。
有什么想法吗?
最佳答案
您有多种选择:
或
- 使用像SmartAssembly这样的工具(商业)
它可以嵌入和合并其他东西(无需更改您的源代码)
或
- code that yourself in less than 10 lines (免费但最小的源代码更改)
将所有需要的依赖项标记为“嵌入式资源”——这样它们就包含在 EXE 文件中……你需要设置一个AssemblyResolve
在运行时从资源中读取并将所需的 DLL 返回给 .NET 运行时的处理程序...
关于c# - 如何将dll合并成一个dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28932074/