Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Integrate ILMerge into Visual Studio Build Process to Merge Assemblies?

I want to merge one .NET DLL assembly and one C# Class Library project referenced by a VB.NET Console Application project into one command-line console executable.

I can do this with ILMerge from the command-line, but I want to integrate this merging of reference assemblies and projects into the Visual Studio project. From my reading, I understand that I can do this through a MSBuild Task or a Target and just add it to a C#/VB.NET Project file, but I can find no specific example since MSBuild is large topic. Moreover, I find some references that add the ILMerge command to the Post-build event.

  1. How do I integrate ILMerge into a Visual Studio (C#/VB.NET) project, which are just MSBuild projects, to merge all referenced assemblies (copy-local=true) into one assembly?

  2. How does this tie into a possible ILMerge.Targets file?

  3. Is it better to use the Post-build event?

like image 649
AMissico Avatar asked Mar 31 '10 19:03

AMissico


People also ask

What is ILMerge?

ILMerge is a utility that can be used to merge multiple . NET assemblies into a single assembly. ILMerge takes a set of input assemblies and merges them into one target assembly. The first assembly in the list of input assemblies is the primary assembly.

What is ILRepack?

ILRepack is a tool that allows you to merge multiple assemblies into a single assembly. This can be useful when you deploy an application that has a few dependencies. In this case, you can merge all the dll and the exe into a single exe file, so it's easier to deploy it. It's also useful if you create a NuGet package.


1 Answers

The "MSBuild ILMerge task" (or MSBuild.ILMerge.Task) NuGet package makes this process quite simple. It defaults to merging any "copy local" references into your main assembly.

Note: Although the packages have similar names, this one is different from ILMerge.MSBuild.Tasks that Davide Icardi mentioned in his answer. The one I'm suggesting here was first published in August 2014.

like image 142
Holistic Developer Avatar answered Oct 05 '22 14:10

Holistic Developer