我找到了以下解决方案:
对于多个Dll:
C:\Program Files (x86)\Microsoft\ILMerge>ILMerge.exe /target:winexe /targetplatform:"v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319" /out:NewExeName.exe SourceExeName.exe DllName1.dll DllName2.dll DllName3.dll
注意:如果您正在尝试加载非 ILOnly 程序集,则
Assembly.Load(block)
无法工作,会抛出异常: 更多细节
我通过创建临时文件并使用以下方法克服了这个问题
Assembly.LoadFile(dllFile)
我之前回答过一个类似的关于 VB.NET
的问题。不过转换应该不会太难。你可以将 DLL
嵌入到你的 Ressource
文件夹中,在第一次使用时,AppDomain.CurrentDomain.AssemblyResolve
事件就会被触发。
如果你想在开发过程中引用它,只需将普通的 DLL
引用添加到你的项目中即可。
该命令应该是以下脚本:
ilmerge myExe.exe Dll1.dll /target:winexe /targetplatform:"v4,c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\" /out:merged.exe /out:merged.exe