I\'m testing out ILMerge for a new project, and although the .exe file seems to be created correctly, it won\'t run.
I have installed ILMerge via the .msi installer (fou
A fully self-contained executable can be created in Visual Studio 2010 easily, and this method does not require ILMerge at all.
Steps:
After this Visual Studio will auto-create a new class called Resources, which you have to use in your new project.
Then you have to compile your program with Visual Studio and that's it.
static void Main(string[] args)
{
// Load your assembly with the entry point from resources:
Assembly start = Assembly.Load((byte[]) Properties.Resources.NameOfDllOrExeInYourResources);
Type t = start.GetType("Foo.Bar.Program");
// Install the resolver event
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
// Find Program.Main in the loaded assembly
MethodInfo m = t.GetMethod("Main", BindingFlags.Public | BindingFlags.Static);
// Launch the application
m.Invoke(null, new object[] { args });
}
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string assemblyName = new AssemblyName(args.Name).Name.Replace('.', '_');
// Locate and load the contents of the resource
byte[] assemblyBytes = (byte[]) Properties.Resources.ResourceManager.GetObject(assemblyName, Properties.Resources.Culture);
// Return the loaded assembly
return Assembly.Load(assemblyBytes);
}