0

I am using Visual Studio 2013.

I have 3 C# class library projects, A, B & C.

A references B

B referencess C

When I compile and build project "A" in visual studio, I see A.dll, B.dll and C.dll in the bin folder of project "A".

Now I planned to merge B.dll and C.dll inside A.dll.

I tried using below ILMerge command but the contents of A.dll are lost.

ilmerge /out:A.dll A.dll B.dll C.dll  /targetplatform:v4

Any idea how can this be achived? I wan't B and C merged in A without loosing A's content.

Thanks.

thinkmmk
  • 487
  • 1
  • 8
  • 22

1 Answers1

1

Consider using a multi-step process as follows by running three commands:

1. create temp assembly from 3 input assemblies.

2. delete original libraryA.dll assembly.

3. rename temp assembly to libraryA.dll.

Example:

3 commands executed on a single line by using "&" separator.

C:\<somepath>\Debug>"C:\<somepath>"\ILMerge.exe /out:temp.dll libraryA.dll libraryB.dll libraryC.dll  /targetplatform:v4 & del /F /Q libraryA.dll & ren temp.dll libraryA.dll

Output (viewed in ILSpy for convenience):

ILSpy showing code from multiple sources merged into single assembly

IMPORTANT: You should consider following this process only with Release builds. If done against debug builds with .pdb files the rename performed in the 3rd step of the example will void the ability to debug the assemblies. related info on SO: here

NOTE: If your intention is to maintain the assembly version of the original libraryA.dll assembly in the process you'll need to get more creative i.e. source the assembly version and subsequently passing the version to the /ver:version argument of ILMerge.exe. If considering running ILMerge as a postbuild event the following links related to getting the version are applicable.

SO: getting version in postbuild event

SO: getting version in commandline

Invoking ILMerge as a postbuild is discussed SO: here

Also note: A question similar to yours was discussed here without an example based answer.

Community
  • 1
  • 1
Elmar
  • 1,236
  • 1
  • 11
  • 16