<h2>Command Line Usage</h2>
The full command line for ILMerge is:
<pre><code>ilmerge [/lib:directory]* [/log[:filename]] [/keyfile:filename [/delaysign]] [/internalize[:filename]]
[/t[arget]:(library|exe|winexe)] [/closed] [/ndebug] [/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>...]
</code></pre>
All options that take arguments can use either <code>:</code> or <code>=</code> as a separator. Options can be in any order, but all of the options must precede the list of input assemblies.
<h2>AllowDuplicateType</h2>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-k">void</span> <span class="pl-en">AllowDuplicateType</span>(<span class="pl-k">string</span> <span class="pl-smi">typeName</span>);</pre>
</div>
The normal behavior of ILMerge is to not allow there to be more than one public type with the same name. If such a duplicate is found, then an exception is thrown. However, ILMerge can just rename the type so that it no longer causes a conflict. For private types, this is not a problem since no outside client can see it anyway, so ILMerge just does the renaming by default. For public types, it is not often a useful feature to have it renamed. However, there are situations where it is needed. In particular, for obfuscated assemblies, it seems that the obfuscator defines an attribute and creates an assembly-level attribute for the obfuscated assembly using that attribute. This would mean that obfuscated assemblies cannot be merged.
So this option allows the user to either allow all public types to be renamed when they are duplicates, or to specify it for arbitrary type names. On the command line, there can be as many options as desired, if followed by a colon and a type name, otherwise just specify it alone with no colon (and type name) to allow all duplicates.
When used through the API, an argument of "null" means to allow all public types to be renamed.
<strong>Default:</strong> no duplicates of public types allowed
<strong>Command line option:</strong> <code>[/allowDup[:typeName]]*</code>
<h2>AllowMultipleAssemblyLevelAttributes</h2>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> <span class="pl-smi">AllowMultipleAssemblyLevelAttributes</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
When this is set before calling Merge, then if the CopyAttributes property (Section 2.7) is also set, any assembly-level attributes names that have the same type are copied over into the target directory as long as the definition of the attribute type specifies that "AllowMultiple" is true.
<strong>Default:</strong> <code>false</code>
<strong>Command line option:</strong> <code>/allowMultiple</code>
<h2>AllowWildCards</h2>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> <span class="pl-smi">AllowWildCards</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
When this is set before calling Merge, any wild cards in file names are expanded and all matching files will be used as input. Note that because the wild card matching is done by a call to Directory.GetFiles, it does not allow the characters ".." to appear in a file name. So if you want to specify a relative path containing ".." to move up a directory, you will have to use it with the "/lib" option (Section 2.20). That option does allow the use of ".." to move up directories.
<strong>Default:</strong> <code>false</code>
<strong>Command line option:</strong> <code>/wildcards</code>
<h2>AllowZeroPeKind</h2>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> <span class="pl-smi">AllowZeroPeKind</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
When this is set before calling Merge, then if an assembly's PeKind flag (this is the value of the field listed as .corflags in the Manifest) is zero it will be treated as if it was ILonly. This can be used to allow C++ assemblies to be merged; it does not appear that the C++ compiler writes the value as ILonly. However, if such an assembly has any non-IL features, then they will probably not be copied over into the target assembly correctly. So please use this option with caution.
<strong>Default:</strong> <code>false</code>
<strong>Command line option:</strong> <code>/zeroPeKind</code>
<h2>AttributeFile</h2>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">string</span> <span class="pl-smi">AttributeFile</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
If this is set before calling Merge, then it specifies the path and filename to an <em>atttribute assembly</em>, an assembly that will be used to get all of the assembly-level attributes such as Culture, Version, etc. It will also be used to get the Win32 Resources from. It is mutually exclusive with the CopyAttributes property (Section 2.7). When it is not specified, then the Win32 Resources from the primary assembly are copied over into the target assembly. If it is not a full path, then the current directory is used.
<strong>Default:</strong> <code>null</code>
<strong>Command line option:</strong> <code>/attr:filename</code>
<h2>Closed</h2>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> <span class="pl-smi">Closed</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
When this is set before calling Merge, then the "transitive closure" of the input assemblies is computed and added to the list of input assemblies. An assembly is considered part of the transitive closure if it is referenced, either directly or indirectly, from one of the originally specified input assemblies and it has an external reference to one of the input assemblies, or one of the assemblies that has such a reference. Complicated, but that is life...
<strong>Default:</strong> <code>false</code>
<strong>Command line option:</strong> <code>/closed</code>
<h2>CopyAttributes</h2>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> <span class="pl-smi">CopyAttributes</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
When this is set before calling Merge, then the assembly level attributes of each input assembly are copied over into the target assembly. Any duplicate attribute overwrites a previously copied attribute. If you want to allow duplicates (for those attributes whose type specifies "AllowMultiple" in their definition), then you can also set the AllowMultipleAssemblyLevelAttributes (Section 2.2). The input assemblies are processed in the order they are specified. This option is mutually exclusive with specifying an attribute assembly, i.e., the property AttributeFile (Section 2.5). When an attribute assembly is specified, then no assembly-level attributes are copied over from the input assemblies.
<strong>Default:</strong> <code>false</code>
<strong>Command line option:</strong> <code>/copyattrs</code>
<h2>DebugInfo</h2>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> <span class="pl-smi">DebugInfo</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
When this is set to true, ILMerge creates a .pdb file for the output assembly and merges into it any .pdb files found for input assemblies. If you do not want a .pdb file created for the output assembly, either set this property to false or else specify the /ndebug option at the command line.
<strong>Default:</strong> <code>true</code>
<strong>Command line option:</strong> <code>/ndebug</code>
<h2>DelaySign</h2>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> <span class="pl-smi">DelaySign</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
When this is set before calling Merge, then the target assembly will be delay signed. This can be set only in conjunction with the <code>/keyfile</code> option (Section 2.13).
<strong>Default:</strong> <code>false</code>
<h2>ExcludeFile</h2>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">string</span> <span class="pl-smi">ExcludeFile</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
This property is used only in conjunction with the Internalize property (Section 2.12). When this is set before calling Merge, it indicates the path and filename that will be used to identify types that are not to have their visibility modified. If Internalize is true, but ExcludeFile is "", then all types in any assembly other than the primary assembly are made non-public. Setting this property implicitly sets Internalize to true.
The contents of the file should be one regular expression per line. The syntax is that defined in the .NET namespace System.Text.RegularExpressions for regular expressions. The regular expressions are matched against each type's full name, e.g., "System.Collections.IList". If the match fails, it is tried again with the assembly name (surrounded by square brackets) prepended to the type name. Thus, the pattern "\[A\].\*" excludes all types in assembly A from being made non-public. (The backslashes are required because the string is treated as a regular expression.) The pattern "N.T" will match all types named T in the namespace named N no matter what assembly they are defined in.
It is important to note that the regular expressions are <em>not</em> anchored to the beginning of the string; if this is desired, use the appropriate regular expression operator characters to do so.
<strong>Default:</strong> ""
<strong>Command line option:</strong> <code>/internalize[:excludeFile]</code>
<h2>FileAlignment</h2>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">int</span> <span class="pl-smi">FileAlignment</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
This controls the file alignment used for the target assembly. The setter sets the value to the largest power of two that is no larger than the supplied argument, and is at least 512.
<strong>Default:</strong> <code>512</code>
<strong>Command line option:</strong> <code>/align:n</code>
<h2>Internalize</h2>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> <span class="pl-smi">Internalize</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
This controls whether types in assemblies <em>other than</em> the primary assembly have their visibility modified. When it is true, then all non-exempt types that are visible outside of their assembly have their visibility modified so that they are not visible from outside of the merged assembly. A type is exempt if its <em>full name</em> matches a line from the ExcludeFile (Section 2.10) using the .NET regular expression engine.
<strong>Default:</strong> <code>false</code>
<strong>Command line option:</strong> <code>/internalize[:excludeFile]</code>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">string</span> <span class="pl-smi">KeyFile</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
<p>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. It can be used with the DelaySign property (Section 2.9) to have the target assembly delay signed. This can be done even if the primary assembly was fully signed.</p>
<p><strong>Default:</strong> <code>null</code></p>
<p><strong>Command line option:</strong> <code>/keyfile:filename</code></p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> <span class="pl-smi">Log</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
<p>When this is set before calling Merge, then log messages are written. It is used in conjunction with the LogFile property. If Log is true, but LogFile is null, then log messages are written to Console.Out. To specify this behavior on the command line, the option "/log" can be given without a log file.</p>
<p><strong>Default:</strong> <code>false</code></p>
<p><strong>Command line option:</strong> <code>/log[:logfile]</code></p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">string</span> <span class="pl-smi">LogFile</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
<p>When this is set before calling Merge, it indicates the path and filename that log messages are written to. If Log is true, but LogFile is null, then log messages are written to Console.Out.</p>
<p><strong>Default:</strong> <code>null</code></p>
<p><strong>Command line option:</strong> <code>/log[:logfile]</code></p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-k">void</span> <span class="pl-en">Merge</span>();</pre>
</div>
<p>Once all desired options are set, this method performs the actual merging.</p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">string</span> <span class="pl-smi">OutputFile</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
<p>This must be set before calling Merge. It specifies the path and filename that the target assembly will be written to.</p>
<p><strong>Default:</strong> <code>null</code></p>
<p><strong>Command line option:</strong> <code>/out:filename</code></p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> <span class="pl-smi">PublicKeyTokens</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
<p>This must be set before calling Merge. It indicates whether external assembly references in the manifest of the target assembly will use full public keys (false) or public key tokens (true).</p>
<p><strong>Default:</strong> <code>true</code></p>
<p><strong>Command line option:</strong> <code>/useFullPublicKeyForReferences</code></p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-k">void</span> <span class="pl-en">SetInputAssemblies</span>(<span class="pl-k">string</span>[] <span class="pl-smi">assems</span>);</pre>
</div>
<p>When used programmatically, each element of the array should contain the path and filename of an input assembly. The first element of the array is considered to be the primary assembly.</p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-k">void</span> <span class="pl-en">SetSearchDirectories</span>(<span class="pl-k">string</span>[] <span class="pl-smi">dirs</span>);</pre>
</div>
<p>If specified, this sets the directories to be used to search for input assemblies. When used programmatically, each element of the array should contain a directory name. When specified on the command line, use a separate "/lib" option for each directory.</p>
<p><strong>Command line option:</strong> <code>/lib:directory</code></p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-k">void</span> <span class="pl-en">SetTargetPlatform</span>(<span class="pl-k">string</span> <span class="pl-smi">platform</span>, <span class="pl-k">string</span> <span class="pl-smi">dir</span>);</pre>
</div>
<p>This method sets the .NET Framework for the target assembly to be the one specified by platform. Valid strings for the first argument are <code>v1</code>, <code>v1.1</code>, <code>v2</code>, and <code>v4</code>;. The <code>v</code> 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 <code>mscorlib.dll</code> is to be found.</p>
<p><strong>Command line option:</strong> <code>/targetplatform:version,platformdirectory</code></p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> <span class="pl-smi">StrongNameLost</span> { <span class="pl-smi">get</span>; }</pre>
</div>
<p>Once merging is complete, this property is true if and only if the primary assembly had a strong name, but the target assembly does not. This can occur when an .snk file is not specified, or if something goes wrong trying to read its contents.</p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">ILMerge</span>.<span class="pl-smi">Kind</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
<p>This controls whether the target assembly is created as a library, a console application or as a Windows application. When it is not specified, then the target assembly will be the same kind as that of the primary assembly. (In that case, the file extensions found on the specified target assembly and the primary assembly must match.) When it is specified, then the file extension of the target assembly must match the specification.</p>
<p>The possible values are <code>ILMerge.Kind.{Dll, Exe, WinExe}</code></p>
<p><strong>Default:</strong> <code>ILMerge.Kind.SameAsPrimaryAssembly</code></p>
<p><strong>Command line option:</strong> <code>/target:(library|exe|winexe)</code></p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
<p>When this is true, then types with the same name are all merged into a single type in the target assembly. The single type is the union of all of the individual types in the input assemblies: it contains all of the members from each of the corresponding types in the input assemblies. It cannot be specified at the same time as <code>/allowDup</code>.</p>
<p><strong>Default:</strong> <code>false</code></p>
<p><strong>Command line option:</strong> <code>/union</code></p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">System</span>.<span class="pl-smi">Version</span> <span class="pl-smi">Version</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
<p>When this has a non-null value, then the target assembly will be given its value as the version number of the assembly. When specified on the command line, the version is read in as a string and should look like "6.2.1.3" (but without the quote marks). The version must be a valid assembly version as defined by the attribute AssemblyVersion in the System.Reflection namespace.</p>
<p><strong>Default:</strong> <code>null</code></p>
<p><strong>Command line option:</strong> <code>/ver:version</code></p>
<div class="highlight highlight-source-cs">
<pre><span class="pl-k">public</span> <span class="pl-smi">bool</span> <span class="pl-smi">XmlDocumentation</span> { <span class="pl-smi">get</span>; <span class="pl-smi">set</span>; }</pre>
</div>
<p>This property controls whether XML documentation files are merged to produce an XML documentation file for the target assembly.</p>
<p><strong>Default:</strong> <code>false</code></p>
<p><strong>Command line option:</strong> <code>/xmldocs</code></p>