c# - Merge all the dependent assemblies to Exe on build -
i have been searching long time how merge dlls project output exe.
i installed vitevic assembly embedder when project built still leaves of dll files is.
since heared ilmerge not found useful support. need tool can merge dlls.
this do:
- store dlls inside folder inside solution (like "libs").
- inside vs change "build action" dlls "embedded resource" - "store" actuall files inside exe.
place code in main method, or anywhere before use of external assemblies:
appdomain.currentdomain.assemblyresolve += currentdomain_assemblyresolve;
also this:
private static assembly currentdomain_assemblyresolve(object sender, resolveeventargs args) { var thisassembly = assembly.getexecutingassembly(); var assemblyname = new assemblyname(args.name); var dllname = assemblyname.name + ".dll"; var resources = thisassembly.getmanifestresourcenames().where(s => s.endswith(dllname)); if (resources.any()) { var resourcename = resources.first(); using (var stream = thisassembly.getmanifestresourcestream(resourcename)) { if (stream == null) return null; var block = new byte[stream.length]; try { stream.read(block, 0, block.length); return assembly.load(block); } catch (ioexception) { return null; } catch (badimageformatexception) { return null; } } } return null; }
Comments
Post a Comment