ILMerge in MSBuild

Use of included script samples are subject to the terms specified at

Written by Jomo Fisher

 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

 <Target Name="AfterBuild">
   <CreateItem Include="@(ReferencePath)" Condition="'%(CopyLocal)'=='true'">
       <Output TaskParameter="Include" ItemName="IlmergeAssemblies"/>
   <Exec Command="&quot;$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe&quot; /out:@(MainAssembly) &quot;@(IntermediateAssembly)&quot; @(IlmergeAssemblies->'&quot;%(FullPath)&quot;', ' ')"/>
   <!--Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')"/-->

 <Target Name="_CopyFilesMarkedCopyLocal"/>


Comments (2)
  1. Jomo Fisher says:

    Jomo Fisher–Over the last few years I’ve been coding mostly in C#–before that, my day-to-day work was…

  2. I realise this is just something you came up in your spare time but one shortcoming is that this task will execute on every build because there is no InputFiles/OutputFiles specified for the task.

    Furthermore, specifying these values correctly is tricky because you’re overwriting an existing build output file when you do the ILMerge, so if you’re not careful you could get into a position where the task never runs because it sees the (non-yet-merged) output file is up to date!

Comments are closed.

Skip to main content