When and how to use ILMerge with Visual Studio Project / Solution

I am developing a mid-size enterprise application. There are many projects / solutions for this. For instance:

  • Company.Data
    • Company.Data.LinqToSql
  • Company.Entities (business objects)
  • Company.BLL

Then I have some applications - for example, the Windows service: MyWindowsService.

When I deploy this (creating an installation project), it sets the load on the DLL from the results of the above projects.

Is this where I should use ILMerge? to create one assembly ... for example, Company.dll?

How can I integrate this into my build process?

+4
source share
1 answer

Question Best Practices ILMerge has good information on why.

When I use ILMerge, I use it to create a single DLL to simplify deployment.

As for How, I can define a separate VS custom project, "Converged.csproj", if you like. In this .csproj file, I define a custom compilation target. This is the boilerplate code that ILMerge executes in all referenced assemblies for a project.

It looks like this:

<Target Name="Compile"> <!-- Outputs="$(IntermediateOutputPath)$(TargetFileName)" --> <!-- Outputs="$(TargetPath)" --> <Message Text="Performing the Ilmerge." /> <!-- in this CreateItem stanza, we collect all the DLLs for the referenced projects --> <CreateItem Include="@(_ResolvedProjectReferencePaths)"> <Output TaskParameter="Include" ItemName="AssembliesToMerge" /> </CreateItem> <!-- This weird bit of hieroglyphics is the assemblies to merge, quoted, and separated by spaces --> <!-- Example: "c:\foo\project1\bin\Debug\ProjectOne.dll" "c:\foo\project2\bin\Debug\ProjectTwo.dll" --> <Message Text="AssembliesToMerge= @(AssembliesToMerge -> '&quot;%(Fullpath)&quot;', ' ')" /> <!-- Message Text="TargetPath= $(TargetPath)" / --> <Message Text="TargetFileName= $(TargetFileName)" /> <!-- produce the merged assembly - putting the output in the "IntermediateOutputPath" eg obj\Debug. --> <!-- it will be copied later by the CopyFilestoOutputDirectory task defined in Microsoft.Common.Targets --> <Error Text="ILMerge cannot be found. You need to download and install ILMerge in order to build DotNetZip." Condition="!Exists('$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe')" /> <Exec Command="&quot;$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe&quot; /t:library /xmldocs /out:&quot;$(IntermediateOutputPath)$(TargetFileName)&quot; @(AssembliesToMerge -> '&quot;%(Fullpath)&quot;', ' ') " /> <!-- for some reason the XML doc file does not get copied automatically from obj\Debug to bin\Debug. --> <!-- we do it here explicitly. --> <Copy SourceFiles="$(IntermediateOutputPath)$(AssemblyName).XML" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)" /> </Target> 
+7
source

All Articles