【问题标题】:Can't embed EPPlus.dll into my exe无法将 EPPlus.dll 嵌入到我的 exe 中
【发布时间】:2014-09-15 17:51:57
【问题描述】:

我需要将 EPPlus.dll 嵌入到我的独立 exe 应用程序中。我不希望它沿着 exe 复制。显然将它作为装配资源包含在内可以解决我的问题。我发现了很多关于如何做到这一点的描述。例如我执行了以下所有操作:

https://www.youtube.com/watch?v=x-KK7bmo1AM

http://adamthetech.com/2011/06/embed-dll-files-within-an-exe-c-sharp-winforms/

Embedding DLL's into .exe in in Visual C# 2010

我仍然收到Could not load file or assembly 'EPPlus.dll'...

你能给我一些想法吗,因为我以前从来没有做过这样的事情?

P.S.:我使用 VS C# 2010 Express

【问题讨论】:

  • 你得到什么错误?
  • 如果该视频不起作用,并且其他方法不起作用......那么我会冒险猜测您没有正确遵循。
  • @Peter 它在 Q...
  • @PaulZahra 我确实重新检查了几次,我确信我正确地遵循了所有步骤。否则我什至不会考虑发布这个问题。
  • @fishmong3r 必须有更多信息吗?使用 ILMerge 的任何方式都应该可以解决您的问题,我过去曾多次使用过它,唯一一次失败是在您使用 WPF 时...

标签: c# .net winforms visual-studio-2010 embed


【解决方案1】:

尝试在您的应用程序中查看此内容:

在program.cs的main方法中:

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

创建事件:

private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    if (args.Name.StartsWith("MyAssembly,"))
    {
        return Assembly.Load(Properties.Resources.MyAssembly_Dll);
    }
    return null;
}

我正在使用类似的东西来动态加载需要其他尚未加载的程序集的程序集,因此我根据需要加载它们。

欢迎评论。

【讨论】:

  • 我添加了这个事件:private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { if (args.Name.StartsWith("EPPlus")) { return Assembly.Load(Properties.Resources.EPPlus); } return null; } 它不起作用。我不能像 EPPlus.dll 一样使用它,就像我将它添加到现有文件一样的资源中,它会删除扩展名。
【解决方案2】:

here 下载 ILMerge,然后安装 ILMerge。

之后,如果您在 32 位系统上,您应该拥有以下文件 C:\Program Files (x86)\Microsoft\ILMerge\ILMerge.exeC:\Program Files\Microsoft\ILMerge\ILMerge.exe

然后执行ILMerge.exe,参数如下/out:OutputExeFile.exe InputExeFile.exe dllfile.dll

在那之后,ILMerge 应该已经合并 ​​InputExeFile.exe 和 dllfile.dll 并将结果存储在 OutputExeFile.exe 中

如果您只是运行 ilmerge,您将获得以下帮助

用法:ilmerge [/lib:directory]* [/log[:filename]] [/keyfile:filename [/delaysign]] [/internalize[:filename]] [/t[arget]:(库|exe|winexe)] [/关闭] [/ndebug] [/ver:version] [/copyattrs [/allowMultiple] [/keepFirst]] [/xmldocs] [/attr:filename] [/目标平台:[,] | /v1 | /v1.1 | /v2 | /v4] [/useFullPublicKeyForReferences] [/wildcards] [/zeroPeKind] [/allowDup:type]* [/union] [/align:n] /out:filename [...]

【讨论】:

  • 你在哪里定义要嵌入的dll?
  • dllfile.dll 是应该嵌入的 dll,如果你有多个,你可以使用 /wildcards 并使用 *.dll 或者只是一个接一个地列出它们..
  • 而且我每次构建新版本的 exe 时都必须执行此过程,对吗?
  • ILMerge 错误:c:\Program Files (x86)\Microsoft\ILMerge>ilmerge.exe /out:RSMailer.exe "C:\Users\user\Google Drive\x\Projects\RSMailer\bin\Release\RSMailer.exe " "c:\Users\user\Google Drive\x\Projects\RSMailer\Resources\EPPlus.dll" An exception occurred during merging: Unresolved assembly reference not allowed: System.Core. at System.Compiler.Ir2md.GetAssemblyRefIndex(AssemblyNode assembly) at System.Compiler.Ir2md.GetTypeRefIndex(TypeNode type) at System.Compiler.Ir2md.WriteTypeDefOrRefEncoded(BinaryWriter target, TypeNode type)
  • @fishmong3r 你试过谷歌那个错误吗? geekswithblogs.net/michelotti/archive/2010/06/02/…
猜你喜欢
  • 2013-05-25
  • 2021-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-21
  • 2012-07-15
相关资源
最近更新 更多