IntroductionILMerge Tasks is a sibling pair of projects that allow you to access ILMerge during your build, enabling you to incorporate referenced .NET assemblies into a combined assembly, removing the need to distribute external assemblies. For example, suppose your program makes use of a zip library, but you want to distribute a single executable. ILMerge allows you to combine your executable and the zip library into a single assembly. You can then distribute that assembly without requiring the end-user to have a copy of the zip library. Using in a BuildIn the case of both MSBuild and NAnt, referencing the ILMerge task is relatively simple, requiring the ILMerge.*.Tasks.dll file to be available and adding a line to the build file. - Note: The first file that you specify in the list of assemblies will be used as the primary assembly. For more information on what effect the primary assembly has, see this page.
NAntTo use the ILMerge task in NAnt, you will need to add the following line to the build file: <loadtasks assembly="NAnt.NAnt.Tasks.dll" /> The syntax to use ILMerge is then as follows: <ilmerge outputfile="Combined.Assembly.exe">
<inputassemblies>
<include name="Primary.Assembly.exe" />
<include name="ZipLib.dll" />
</inputassemblies>
</ilmerge>MSBuildTo use the ILMerge task in MSBuild, you will need to add the following line to the build file: <UsingTask TaskName="ILMerge.MSBuild.Tasks.ILMerge"
AssemblyFile="ILMerge.MSBuild.Tasks.ILMerge"/> The syntax to use ILMerge is then as follows: <ItemGroup>
<MergeAsm Include="Primary.Assembly.exe" />
<MergeAsm Include="ZipLib.dll" />
</ItemGroup>
<ILMerge InputAssemblies="@(MergeAsm)" OutputFile="Combined.Assembly.exe" />Common AttributesThe ILMerge task attributes used in both the NAnt and MSBuild tasks are the same, with the caveat that the NAnt schema prefers all-lowercase attribute names and MSBuild prefers PascalCase attribute names. The names below use the MSBuild schema. To use them in NAnt, just lowercase the attribute name. AttributeFile- Type: String
- Default: null
The assembly from which to load all assembly-level attributes. Mutually exclusive with CopyAttributes (If both are set, an error will be logged). Closed- Type: Boolean
- Default: false
CopyAttributes- Type: Boolean
- Default: false
DebugInfo- Type: Boolean
- Default: true
When set, any .pdb files that are found for the input assemblies are preserved into a .pdb file for the target assembly. ExcludeFile- Type: String
- Default: null
Has no effect if Internalize == false Internalize- Type: Boolean
- Default: false
LibraryPath- Type: FileSet in NAnt, TaskItem in MSBuild
- Default: { "." }
Log- Type: Boolean
- Default: false
LogFile- Type: String
- Default: null
Has no effect if Log == false OutputFileKeyFile- Type: String
- Default: null
InputAssemblies- Type: FileSet in NAnt, TaskItem in MSBuild
- Required
Target- Type: String in Nant, ILMerge.Kind in MSBuild
- Default: SameAsPrimaryAssembly
Valid values are (lowercased in NAnt): WinExe, Exe, Library, SameAsPrimaryAssembly
|
To get the ILMerge MSBuild task to work I had to change your example to:
<UsingTask TaskName="ILMerge.NAnt.Tasks.ILMerge" AssemblyFile="C:\Program Files\Microsoft\ILMerge\ILMerge.MSBuild.Tasks.dll" />
I don't believe your NAnt example is correct.
After experimenting, I think a correct example would be:
<ilmerge outputfile="Combined.Assembly.exe"> <assemblies> <include name="Primary.Assembly.exe" /> <include name="ZipLib.dll" /> </assemblies> </ilmerge>As a follow up to my previous comment, is it possible to tell the NAnt task where it can locate the ILMerge.exe?
I was unable to fully get the NAnt task to work because I couldn't figure out how to do so. Perhaps the NAnt task could try loading the .exe from the default install path for ILMerge (C:\Program Files\Microsoft\ILMerge)
I downloaded ILMerge from the Microsoft site (version 2.8.422.0) -- the NAnt library is tied to 2.0.7.228.
I guess I have to download the source and recompile. You should consider bundling ILMerge.exe with your download.
Nope did not work with Nant! Said something about could not load the ILMerge.NAnt.Tasks.dll assembly!
I had the same problem. I think it's because my tools\ directory and consequently ilmerge.exe is a network share, and .net is having a hard time finding this reference. I wrote my own version of ILMergeTask which extends ExternalProgramBase?. So you can pass it the location of the ilmerge.exe.
http://esuyer.blogspot.com/2009/07/custom-nant-ilmerge-task-no-assembly.html http://esuyer.blogspot.com/2009/07/custom-nant-ilmerge-task-no-assembly.html
No assembly required. You can paste this right into your NAnt script.