Merging My Assemblies with ILMERGE

I’ve been working on my VisioAutomation project for years now - it appeared on CodePlex in 2009 if I recall correctly but existed for a few years before that. In any case, as the library has grown, one thing I was never satisfied with was the number of DLLs that needed to be included to take advantage of the library completely. I really wanted one DLL that took care of everything.

For example, let’s look at my PowerShell module for Visio 2010 - called VisioPS (you can download VisioPS here). Below is what bin/Debug looked like a few days ago.

In Yellow are all the DLLs my VisioAutomation requires to work.

The Green ones are “helper” DLLs – for those 3rd party DLLs.



I wanted this to be much simpler. Thanks to ILMERGE. It has gotten much better. Below you see a big reduction in the number of DLLs.




ILMERGE helped me get rid of all the Yellow items. Then I incorporated the Green items into VisioAutomation.DLL.

For reference here is the exact MSBUILT task I am using to perform the merging of the assemblies.

<Target Name="AfterBuild">
  < CreateItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(Extension)'=='.dll'">
    <Output ItemName="AssembliesToMerge" TaskParameter="Include" />
  <Exec Command="&quot;C:\Program Files (x86)\Microsoft\ILMerge\ILMerge.exe&quot; /out:@(MainAssembly) /targetplatform:v4,$(MSBuildToolsPath) &quot;@(IntermediateAssembly)&quot; @(AssembliesToMerge->'&quot;%(FullPath)&quot;', ' ')" />
  <Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
< /Target>


  • To keep things consistent ILMERGE is run for both debug and retail builds
  • This is run only on the VisioAutomation.DLL
  • You can download ILMERGE here.
  • I haven’t decided yet whether it is a good idea to merge VisioAutomation.DLL and VisioAutomation.Scripting.DLL. Of course I wouldn’t use ILMERGE for that, just move the code from one project to another. That’s what I did for the Green items in the original list.
  • Yes, that is a Python file you see in the screenshots 🙂 I’ll clean that up later.

Comments (1)

  1. Ankit Singh says:

    Can you give idea of how you did it ?

Skip to main content