Library code snippets

Merge an .exe and a .dll into one .exe

We made a command line tool which takes parameters and sends e-mails. We wanted to distribute this as an .exe but couldn't because it referenced a .dll. This meant that we had to send along the .dll and that it had to be in the same directory as the .exe. We wanted a way to have just one .exe but Visual Studio .NET doesn't offer this (a linker). Luckily, at the Microsoft Research Download Page there is a free tool called ILMerge which does just this. This is how you use it:

  1. download ILMerge
  2. put "ILMerge.exe" in your \WINNT directory
  3. In VS.NET, right click project, Properties, Common Properties, Build Events
  4. In "Post-build Event Command Line" enter:
    ilmerge /out:$(TargetDir)YOURAPPNAME.exe $(TargetPath) $(TargetDir)YOURDLLNAME.dll
  5. Then compile the Release version (not the debug version).
  6. In your "bin\Release" directory, you will find a YOURAPPNAME.exe which can be run on its own without the .dll.

Comments

  1. 27 Apr 2005 at 18:54

    Did you ever find a solution to automating the obfuscation process?  I am doing it currently using preemptive's Dotfuscator Professional Edition by adding a VS.NET Dotfuscator project to my solution, and I set the output path of the Dotfuscator project to the Release folder of my EXE project and it works beautifully.  It also generates the mappings in a map.xml file and I have added the EXE and the map.xml to source code control so that I always have the mappings that went with the EXE.

  2. 30 Dec 2004 at 02:22

    Hi,
    (you may long have solved or forgotton about this problem, but let me reply anyway.)
    This probablly won't help much, but I just want to let you know it DOES work sometimes.
    It seems your command line contains no problem.


    My command line was like:
    ILMerge.exe /wildcards /t:winexe /out:resulting.exe needsDLLs.exe *.dll


    where my needsDlls.exe(developed with c# in Delphi 2005) did not run without Interop.AxShdocVw.dll and Interop.ShdocVw.dll present in the same directory, and, as you may know, the "/wildcard" option allows the use of the '*.dll' to match all dll files in that directory.  I tried running resulting.exe after deleting the dlls from the folder and it worked fine.


    Just in case, if you are trying to pack an unmanaged (i.e. activeX or conventional c-type) dll into merged.exe, that probably won't work. (The name 'classlibrary1.dll' smacks of one.) If so, try merging only managed-code dlls into one.exe and leave the unmanaged dll in c:\windows\system32 or its equivalent where they belong.  In my case, I would not try packing shdocvw.dll into my executable.
    If I'm wrong, just laugh at it and please don't accuse me of assuming somehitng that you have not done :-).


    I hated having to have the two interop dlls in the same folder as my .exe file, but having to reference a separate dll for the underlying ActiveX object in the system folder was not a problem.  So, ILMerge solved the problem.

  3. 24 Jul 2004 at 09:12
    hi, to complete your post: this does not work with VB.NET, only C#

    So what I did is try to do it manually. This works, but the problem is: I need more then 1 dll file to be merged.
    I tried entering more names but it does not seem to work. Here is my command line:

    (ilmerge copied to the same dir)

    ilmerge /out: merged.exe mycompiledprog.exe bass.dll basslib2.net.dll classlibrary1.dll

    Anyone who can help?
  4. 09 Apr 2004 at 14:38

    can anyone, think of the way to obfuscate the .dll and .exe files after the service is deployed on the machine.


    I am tring to obfuscate the application via Aspose obfuscator, but the problem is - I want to first deploy the application and then obfuscate the files, which can be created simply on the machine that i am working on just by simple easy command. but wondering how can that be done on the server, or the machine on which the test is performed.


    another is issue is when the obfuscation is done it just addes the files to a new folder and then I think i can try deleting the other .dll but that can be possible when i know each and everyname of the dll file that is present there.


    does there a way exist to find all the .dll files that have been obfuscated and that have not been obfuscated(inorder to delete the files that have been obfuscated, but only delete the files that are in the original form)
    if you don't understand the problem please tell me I can try to explain in much detail.
    Thanks!


  5. 01 Jan 1999 at 00:00

    This thread is for discussions of Merge an .exe and a .dll into one .exe.

Leave a comment

Sign in or Join us (it's free).

Edward Tanguay Edward Tanguay updates his personal web site tanguay.info weekly with code, links, quotes and thoughts on web development. Sign up for the free newsletter.
AddThis

Related podcasts

  • A Practical Look at Silverlight 2 Part 1

    Now that Silverlight 2 is at the Olympics and making a big splash, we wanted to explore this fascinating technology more. Microsoft Silverlight 2 is a cross-browser, cross-platform, and cross-device plug-in for delivering the next generation of .NET based media experiences and rich interactive ap...

Events coming up

  • Nov 18

    15 Minutes of Fame

    Dresher, United States

    This is a yearly tradition. We select 10 of the favorite speakers from monthly meetings, code camps, and hands on labs. Each one does a 15 minute talk on their favorite .NET technology. This is our 10th anniversary so we plan a gala event with special prizes and refreshments.

Want to stay in touch with what's going on? Follow us on twitter!