Hack the Build: Use ILMerge and MSBuild to Combine Multiple Assemblies into One
Jomo Fisher–Over the last few years I've been coding mostly in C<before that, my day-to-day work was done in C++. I don't miss much about C++, but one of the things that I do miss is the ability to link many .LIB files into a single DLL or EXE
I've known that it was possible to do this in .NET (with LINK.EXE or ILMERGE.EXE) but there is no built-ine support in VS2005 for doing this.
This weekend, I decide to see what it would take to plug ILMERGE into the regular C# build system. It's pretty simple to get basic support.
(2) Save the this file to C:\Program Files\msbuild\Ilmerge.CSharp.targets
(3) In VS2005, right-click on the projectin solution explorer and select "Unload Project"
(4) Right-click again and pick 'Edit MyApp.csproj'
(5) Replace the <Import> line with <Import Project="$(MSBuildExtensionsPath)\Ilmerge.CSharp.targets" /> and save.
(6) Right-click again on the project in solution explorer and select "Load Project"
Now, the project you modified will automatically have all referenced assemblies merged-in. Only the assemblies marked "Copy Local" will be merged so system assemblies and GAC assemblies won't be merged by default.
You only need to modify the projects you would like to have merging. In other words, you can have mixed merged and unmerged projects in the same solution.
This posting is provided "AS IS" with no warranties, and confers no rights.
ILMerge in MSBuild
5 Mar 2006 5:31 PM
<!<span style="font-family: "PT Serif"; font-size: 16px; line-height: 24px; color: rgb(121, 121, 121);"–<
Use of included script samples are subject to the terms specified athttp://www.microsoft.com/resources/sharedsource/licensingbasics/permissivelicense.mspx
Written by Jomo Fisher
<span style="font-family: "PT Serif"; font-size: 16px; line-height: 24px; color: rgb(121, 121, 121);"–<>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<CreateItem Include="@(ReferencePath)" Condition="'%(CopyLocal)'=='true'">
<Output TaskParameter="Include" ItemName="IlmergeAssemblies"/>
<Exec Command=""$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe" /out:@(MainAssembly) "@(IntermediateAssembly)" @(IlmergeAssemblies->'"%(FullPath)"', ' ')"/>
<!<span style="font-family: "PT Serif"; font-size: 16px; line-height: 24px; color: rgb(121, 121, 121);"–<Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')"/–>