Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

Merging Assemblies With MSBuild

Elberet edited this page Jul 6, 2011 · 1 revision

The following assumes that you are using MSBuild to build your plugin assembly. This is the case if you are using Visual Studio; if you are using any other IDE, you need to find out which build system that IDE uses.

ILMerge

ILMerge is a tool for merging multiple .NET™ assemblies together and is available for download from the Microsoft® Download Center here. Once you have downloaded and installed ILMerge, read on.

Hacking the Build

While Visual Studio does not let you fine-tune the build process to the degree required here from within the IDE itself, you can edit project files manually without breaking Visual Studio:

  1. Close Visual Studio. VS seems to cache project files, even if the project is unloaded and reloaded, so a restart is required whenever you edit the project file outside of Visual Studio.

  2. Open your project file in a text editor of your choice and insert this XML block at the end of the file, just above </Project>:

     <Target Name="AfterBuild">
       <CreateItem Include="@(ReferencePath)" Condition="'%(CopyLocal)'=='true'">
         <Output TaskParameter="Include" ItemName="IlmergeAssemblies" />
       </CreateItem>
       <Exec Command="&quot;$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe&quot; /out:@(MainAssembly) &quot;@(IntermediateAssembly)&quot; @(IlmergeAssemblies->'&quot;%(FullPath)&quot;', ' ') &gt;E:\Temp\test.txt" />
     </Target>
     <Target Name="_CopyFilesMarkedCopyLocal" />
    
  3. Note that the AfterBuild target will be considered after the Post-build event command line editable in the Visual Studio project properties. If you want to copy the finished assembly into MusicBee's plugin folder after every build, you must add another <Exec /> command to the project file, since at the time when the Post-build event is run, the assemblies haven't been merged yet. For example, I have this just below the first <Exec... line:

       <Exec Command="copy @(MainAssembly) &quot;C:\Program Files (x86)\MusicBee\Plugins\&quot;" />
    
Clone this wiki locally