Friday, 9 April 2010

Using ILMerge to Merge Several DLLS into a Single Library

We are building a shared library for our project and it includes a few references to other libraries as dependencies.  We don’t want to have to share all these, so I was hoping to use ILMerge to merge them into a single assembly that we could share.  I’ll use the continuous integration server to produce the dll and the projects can include it from the output location.  There’s relatively little information about how to use ILMerge, so I may as well blog about it.

Mind you, after a few tests I realised why.   After setting my system path to point to the installation of ILMerge, all you really need is the command line:

Ilmerge.exe /out:..\build\Publish\ProviderRedirection.dll ..\build\$(Configuration)\ProviderRedirectionSystem\ProviderRedirectionSystem.dll

So the next step is to integrate it into my MSBuild script.  Here we want to make sure that every DLL for the class library is merged into a single dll so we make an item group of the DLLS in the project and then pass them through to the command line.


<!--This group of files will be published as part of the website.-->
Exclude="..\**\.svn\**;..\**\*.pdb;..\build\Release\MySystem\MySystem.dll" />


<Target Name="PublishMySystem" DependsOnTargets="Clean;All">
<Message Text="Merging @(MyBinaries)"></Message>
<Exec Command="Ilmerge.exe /out:..\build\Publish\MySystem.dll ..\build\Release\MySystem\MySystem.dll @(MyBinaries->'&quot;%(FullPath)&quot;', ' ')" />


Barry said...

I am a little confused by your comment 'Mind you, after a few tests I realised why.' - I'm interested in using ilmerge myself but am keen to know if you found this to be the solution you were hoping it would be?



Odd said...

To clarify, there's little information because it's so simple to use. The command line itself shows you most of the information you need to figure it out.