Tuesday, January 25, 2011

ILMerge to combine multiple DLLs

I have a solution with several projects and some third party DLLs referenced on the side. One of the projects is a sample windows forms application and will be provided to the client as is (including source). For the other projects the client will only be given files to reference from their projects.

ILMerge is a command line tool that can be called as a post-build step to combine the bin output of all the Class Library projects into a single DLL (and PDB).

I added a post-build step to the last class library that gets built before the forms application. This combines all the library DLLs into a single file that is then referenced by the forms application. Note that I put the ILMerge.exe in a path within the solution.

..\..\..\References\ILMerge\ILMerge.exe /out:..\..\..\References\SingleFileToBeReferencedBySampleFormsApp.dll
 ClassLibrary1Output.dll ClassLibrary2Output.dll ClassLibrary3Output.dll ThirdPartyDotNetLibrary.dll