Statically link with ILMerge
Today Ralf & I were looking at ways to bundle up a bunch of .Net assemblies into a single assembly for use within our group; the goal to expose only the functionality we want and only need to reference one assembly in our projects. Enter command line app ILMerge by Michael Barnett of Microsoft Research which lets you merge a set of dlls into a single assembly and selectively hide functionality by changing public access modifiers to internal. The first assembly you specify on the command line is the primary one and it's types maintain their access modifiers, the subsequent assembles are the ones that can be hidden by using ILMerge's ExcludeFile parameter where you can specify a file which in turn contains a list of regular expressions for the types you would like to keep public. When you merge the assemblies if you have also written XML code documentation files these get merged too, so you even get to keep the intellisense tooltips on the classes and functions you have documented with /// comments. For C# projects you can specify XML documentation output in the project's Visual Studio build properties, and for F# projects you can use the command line -doc filename option. To quickly check if we were getting the desired results in our target assembly we used the ILdasm tool to walk through our types. While checking the output we noticed that by default in the current F#, triple slash XML comments get embedded in the assembly for use in Visual Studio for tooltips; but if you are already generating seperate XML documentation it is possible to turn off this feature with the --no-interface-data command line option. So in summary ILMerge appears to be a great, highly customisable tool that lets you distribute a single assembly exposing just the functionality you want to expose (just like linking good old .Lib files in C++ :)).
Phil
Comments
Anonymous
January 01, 2003
PingBack from http://www.mundositio.com/2008/05/31/statically-link-with-ilmerge/Anonymous
February 06, 2011
The comment has been removed