Thursday, January 4, 2018

Merge assemblies using ILMerge

Sometimes we do have requirement of using external dll in a plugin. So, to register our plugin we should merge it to make a single dll. Here we will be using ILMerge for merging the dlls. ILMerge is an utility which merges multiple .NET assemblies into a single assembly.

Download ILMerge utility here

Ilmerge.exe [/lib:directory]* [/log[:filename]] [/keyfile:filename [/delaysign]] [/internalize[:filename]] [/target]:(library|exe|winexe)] [/closed] [/debug] [/ver:version] [/copyattrs [/allowMultiple]] [/xmldocs] [/attr:filename] ([/targetplatform:<version>[,<platformdir>]]|v1|v1.1|v2|v4) [/useFullPublicKeyForReferences] [/zeroPeKind] [/wildcards] [/allowDup[:typename]]* [/allowDuplicateResources] [/union] [/align:n] /out:filename <primary assembly> [<other assemblies>...]

Out of all the options we basically use four major options to merge , below is the sample example for ILMerge.

ILMerge.exe /out:"C:\ILMerge\Primary.dll" /lib:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319" /targetplatform:"v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319" /keyfile:"Your path to .snk file" "C:\Main\Primary.dll" "C:\Main\Secondary.dll"

/out:  This must be set before calling Merge. It specifies the path and filename that the target assembly will be written to.

/lib: If specified, this sets the directories to be used to search for input assemblies. We do set the path for .Net Framework 4.0.

/targetplatform: This method sets the .NET Framework for the target assembly to be the one specified by platform. Valid strings for the first argument are "v1", "v1.1", "v2", and "v4". The "v" is case insensitive and is also optional. This way ILMerge can be used to "cross-compile", i.e., it can run in one version of the framework and generate the target assembly so it will run under a different assembly. The second argument is the directory in which mscorlib.dll is to be found

/keyfile: When this is set before calling Merge, it specifies the path and filename to a .snk file. The target assembly will be signed with its contents and will then have a strong name

No comments:

Post a Comment