Pages

Saturday, July 25, 2009

How to merge file dll to exe C#

Today, at work I have to create a demo application using C# to automatically launch IE and open certain URL and modify its form input. Since this task requires SHDocVW and MSHTML components, I have to let dll files accompany the exe file. But there is a requirement that the application shall consist of one single executable. Hence, I have to find a way to merge the dll to executable. Gladly, after searching in the internet, I found that it is very simple.

The step is as follows:

  1. Download ILMerge from microsoft site here.

  2. Install and copy the ilmerge.exe to windows directory or simply make the PATH to installation directory (to let us execute ilmerge.exe from anywhere)

  3. Go to the project properties, Build Events. Assuming the dll files are in the same directory of the Target, enter the following code to the post built even command line:
    ilmerge /wildcards /out:$(TargetDir)my-final-app.exe $(TargetPath) $(TargetDir)*.dll

To have a better understanding on how to execute ilmerge, I suggest to read the ilmerge.doc which is located in the installation folder.

That's all :)