sirp Posted April 6, 2011 Posted April 6, 2011 Found a nice snippetit's from the book OReilly.C.Sharp.4.0.in.a.NutshellPacking a single-file executable:using System;using System.IO;using System.Reflection;using System.Collections.Generic;public class Loader{ static Dictionary <string, Assembly> libs = new Dictionary <string, Assembly>(); static void Main() { AppDomain.CurrentDomain.AssemblyResolve += FindAssem; Program.Go(); } static Assembly FindAssem (object sender, ResolveEventArgs args) { string shortName = new AssemblyName (args.Name).Name; if (libs.ContainsKey (shortName)) return libs [shortName]; using (Stream s = Assembly.GetExecutingAssembly(). GetManifestResourceStream ("Libs." + shortName + ".dll")) { byte[] data = new BinaryReader (s).ReadBytes ((int) s.Length); Assembly a = Assembly.Load (data); libs [shortName] = a; return a; } }}public class Program{ public static void Go() { // Run main program... }}nutshell
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now