-
Notifications
You must be signed in to change notification settings - Fork 0
Merging Assemblies With MSBuild
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 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.
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:
-
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.
-
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=""$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe" /out:@(MainAssembly) "@(IntermediateAssembly)" @(IlmergeAssemblies->'"%(FullPath)"', ' ') >E:\Temp\test.txt" /> </Target> <Target Name="_CopyFilesMarkedCopyLocal" />
-
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) "C:\Program Files (x86)\MusicBee\Plugins\"" />