R – Is it possible to successfully merge transitive assembly references with ILMerge

antlrilmergenetstringtemplate

I'm trying to use ILMerge to internalize some transitively referenced assemblies into an assembly I'm referencing to eliminate conflicts with those transitive dependencies elsehwere in my project.

In particular, I'm referencing Antlr3.StringTemplate (hereafter referred to as AS, available here: http://www.stringtemplate.org/download.html). It references Antlr3.Runtime.Debug (ARD) and Antlr3.Runtime (AR). ARD itself also references AR. In ASCII-art, that's:

AS ---> ARD
\        |
 \       v
  \---> AR

Because another assembly I'm using, NHibernate 2.1, depends on different, incompatible version of AR, I wanted to use ILMerge to merge and internalize AR into AS. In theory, I think this should work; however, I'm having trouble executing the theory.

No matter what permutations and options I try, I end up with an error of the following form:

ILMerge.Merge: The assembly
'Antlr3.Runtime.Debug' was not merged
in correctly. It is still listed as an
external reference in the target
assembly.

Is what I'm trying to accomplish with ILMerge even possible?

Best Answer

When you run ILMerge from the command line (or within an MSBuild task), of all the assembly files you list out to be merged, it is the first one that is considered the primary assembly when the merging begins. If you haven't already, ensure that the AS assembly filename is listed first in you list of merging assemblies.

Related Topic