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:

  1. store dlls inside folder inside solution (like "libs").
  2. inside vs change "build action" dlls "embedded resource" - "store" actuall files inside exe.
  3. 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

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -