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
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.
(1) Download and install ILMerge MSI: http://www.microsoft.com/downloads/details.aspx?FamilyID=22914587-b4ad-4eae-87cf-b14ae6a939b0&displaylang=en
(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"
(7) Build.
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.
http://blogs.msdn.com/b/jomo_fisher/archive/2006/03/05/ilmerge-in-msbuild.aspx
ILMerge in MSBuild
5 Mar 2006 5:31 PM
<!
Use of included script samples are subject to the terms specified athttp://www.microsoft.com/resources/sharedsource/licensingbasics/permissivelicense.mspx
Written by Jomo Fisher
<Project
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003 ">
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
<CreateItem Include="@(ReferencePath)" Condition="'%(CopyLocal)'=='true'">
<Output TaskParameter="Include" ItemName="IlmergeAssemblies"/>
</CreateItem>
<Exec Command=""$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe" /out:@(MainAssembly) "@(IntermediateAssembly)" @(IlmergeAssemblies->'"%(FullPath)"', ' ')"/>
<!
</Target>
<Target Name="_CopyFilesMarkedCopyLocal"/>
</Project>