Merge assemblies with ILMerge
ILMerge is a tool for merging assemblies together, which is very useful for easy deployments. Instead of deploying 10 dlls you can deploy one. When distributing applications out to customers you really want to make the application as simple as possible, and the most simple application is one that consist of only one exe.
ILMerge in .NET 4
I had some problems using ILMerge with .NET 4 dlls, but managed to get around my problems with some extra parameters. Here's how you merge dlls into a single DLL using ILMerge.
ilmerge.exe /lib:"C:\Windows\Microsoft.NET\Framework\v4.0.30319" /lib:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies" /t:dll /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /out:MyApplication.merged.dll MyApplication.dll ReferenceAssembly1.dll ReferenceAssembly2.dll ReferenceAssembly3.dll
It's easy to merge dlls into an exe, just by changing target type. Use your original exe as the first argument after option parameters.
ilmerge.exe /lib:"C:\Windows\Microsoft.NET\Framework\v4.0.30319" /lib:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies" /t:exe /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /out:MyApplication.merged.exe MyApplication.exe ReferenceAssembly1.dll ReferenceAssembly2.dll ReferenceAssembly3.dll
In your build process
You can easily apply this in your build process.
- Copy ilmerge.exe to somewhere in your project path. I placed mine in a folder called External Tools.
- Right click your main project in Visual Studio and select Properties / Build Events.
- I use the following to merge assemblies for TogglChart into one dll.
"$(SolutionDir)External Tools\ilmerge" /lib:"C:\Windows\Microsoft.NET\Framework\v4.0.30319" /lib:"D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies" /t:dll /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /out:"$(TargetDir)$(SolutionName).merged.dll" "$(TargetDir)TogglChart.Lib.dll" "$(TargetDir)Newtonsoft.Json.dll" "$(TargetDir)ZedGraph.dll"
comments powered by Disqus