Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When & How to use ILMerge with Visual Studio Project / Solution

I'm developing a medium sized enterprise application. There are many projects / solutions to this. For example:

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

I then have some applications - for example a windows service: MyWindowsService.

When i deploy this (by creating a setup project) it installs a load of DLL's from the output of the above mentioned projects.

Is this where i should be using ILMerge? to create one assembly.... Company.dll for example?

How would i go about integrating this into my build process?

like image 784
Alex Avatar asked Oct 13 '09 17:10

Alex


People also ask

What is the grammar of when?

We use when as a conjunction meaning 'at the time that'. The clause with when is a subordinate clause (sc) and needs a main clause (mc) to complete its meaning.

What type of adverb is when?

Whenever an adverb is used to relate or connect or join any two sentences, we use relative Adverbs. These Adverbs are just three- where, when, and why.

Is when an adverb or conjunction?

The word “when” has multiple functions. It can be used as an adverb, conjunction, pronoun, and noun. This word is categorized as an adverb because it modifies a verb, and adjective, or another adverb by indicating the time.


1 Answers

The question ILMerge Best Practices has good info on why.

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

As to How, I define a separate, custom VS project, "Converged.csproj" if you like. In that .csproj file I define a custom Compile target. It is boilerplate code, that performs an ILMerge on all the referenced assemblies for the 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>
like image 183
Cheeso Avatar answered Sep 19 '22 17:09

Cheeso