关于.dll和.exe封装成一个.exe的方法总结
1.使用ILmerge DOS命令行加载。进入ILmerge 所安装的位置。/out:输出文件,/log 所依赖的文件 cd C:Program Files (x86)MicrosoftILMerge ILmerge /ndebug /target:dll /out:C:C.dll /log C:A.dll C:B.dll 链接: 提取码:gwpp
2.用图形界面的ILmerge GUI 链接:https://pan.baidu.com/s/16MJGd1UpmHAPlzthXPUWPQ 提取码:cvip
3.有一个方法,可以占时合成一个exe,执行的时候,还是会释放。在main.cs中加
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); string path = Application.StartupPath + "\"; string dllFileName = "IrisSkin2.dll"; //******加载IrisSkin2.dll****** if (!File.Exists(path + dllFileName)) //文件不存在 { FileStream fs = new FileStream(path + dllFileName, FileMode.CreateNew, FileAccess.Write); byte[] buffer = GetData.Properties.Resources.IrisSkin2;//{GetData是命名空间} fs.Write(buffer, 0, buffer.Length); fs.Close(); } Application.Run(new GDForm()); }
4.使用工具菜单选择NuGet 控制台命令,在控制台中输入Install-Package Costura.Fody 安装 PM> Install-Package Costura.Fody -Version 1.6.2 设置需要的DLL配置考入本地,重新编译。
5.使用winara 其实是隐藏文件。
6.最好用的方法。 在Resources下面添加.dll。DLL的“生成操作”弄成“嵌入的资源”
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("xtea加密测试工具.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly()); byte[] bytes = (byte[])rm.GetObject(dllName); return System.Reflection.Assembly.Load(bytes); } public Form1() { AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); InitializeComponent(); xtea_securityInit(); }
上一篇:
通过多线程提高代码的执行效率例子