【发布时间】:2012-08-26 21:34:45
【问题描述】:
我使用此代码将所有 dll 嵌入到应用程序 exe 文件中,但此代码只能嵌入一个 dll。我搜索其他代码,但都是一样的。
public App()
{
AppDomain.CurrentDomain.AssemblyResolve +=new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string dllName = args.Name.Contains(',') ? args.Name.Substring(0, args.Name.IndexOf(',')) : args.Name.Replace(".dll","");
dllName = dllName.Replace(".", "_");
if (dllName.EndsWith("_resources")) return null;
System.Resources.ResourceManager rm = new System.Resources.ResourceManager(GetType().Namespace + ".Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());
byte[] bytes = (byte[])rm.GetObject(dllName);
return System.Reflection.Assembly.Load(bytes);
}
要使用 ILmerge,我的 dll 有问题。所以我不能用这个。 我怎样才能做到这一点?
【问题讨论】:
-
我使用第三方程序集,希望用户无法理解这一点。
-
你已经成功了,我看不懂。如果 ILMerge 失败,则 Assembly.Load(byte[]) 很可能也会失败。它无法加载包含本机代码的 DLL。将您的可执行文件打包到一个名为 setup.exe 的文件中,然后使用安装项目创建一个。