0
votes

I'm trying to merge a library into another library with ILMERGE.

The primary assembly is about 33 kb large, the assembly to be merged with it is about 5 Mb. After merging, the new assembly is 1.2 Mb in size.

I would like some help understanding the log from the merge, because I don't think the merged assembly should be so much smaller.

Here is the log:

ILMerge version 2.13.307.0 Copyright (C) Microsoft Corporation 2004-2006. All rights reserved. ILMerge /lib:C:\Windows\Microsoft.NET\Framework\v4.0.30319 /lib:C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PublicAssemblies /t:dll /log:merge.log /zeropekind /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /out:ericsconnectionsM.dll ericsconnections_32.dll chilkatdotnet45.dll Set platform to 'v4', using directory 'C:\Windows\Microsoft.NET\Framework\v4.0.30319' for mscorlib.dll Running on Microsoft (R) .NET Framework v4.0.30319 mscorlib.dll version = 4.0.0.0 The list of input assemblies is: ericsconnections_32.dll chilkatdotnet45.dll Trying to read assembly from the file 'C:\Users\eervawo\Documents\Visual Studio 2010\Projects\EricsConnections\EricsConnections\bin\Debug\ericsconnections_32.dll'. Successfully read in assembly. There were no errors reported in EricsConnections_32's metadata. Trying to read assembly from the file 'C:\Users\eervawo\Documents\Visual Studio 2010\Projects\EricsConnections\EricsConnections\bin\Debug\chilkatdotnet45.dll'. Can not find PDB file. Debug info will not be available for assembly 'chilkatdotnet45.dll'. Successfully read in assembly. There were no errors reported in ChilkatDotNet45's metadata. Checking to see that all of the input assemblies have a compatible PeKind. EricsConnections_32.PeKind = ILonly, Requires32bits ChilkatDotNet45.PeKind = 0 The effective PeKind for 'ChilkatDotNet45' will be considered to be: ILonly All input assemblies have a compatible PeKind value. AssemblyResolver: Assembly 'EricsConnections_32' is referencing assembly 'System.Xml.Linq'. AssemblyResolver: Attempting referencing assembly's directory. AssemblyResolver: Did not find assembly in referencing assembly's directory. AssemblyResolver: Attempting input directory. AssemblyResolver: Did not find assembly in input directory. AssemblyResolver: Attempting user-supplied directories. Resolved assembly reference 'System.Xml.Linq' to 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Xml.Linq.dll'. (Used a client-supplied directory.) Can not find PDB file. Debug info will not be available for assembly 'System.Xml.Linq'. AssemblyResolver: Assembly 'EricsConnections_32' is referencing assembly 'System.Core'. AssemblyResolver: Attempting referencing assembly's directory. AssemblyResolver: Did not find assembly in referencing assembly's directory. AssemblyResolver: Attempting input directory. AssemblyResolver: Did not find assembly in input directory. AssemblyResolver: Attempting user-supplied directories. Resolved assembly reference 'System.Core' to 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Core.dll'. (Used a client-supplied directory.) Can not find PDB file. Debug info will not be available for assembly 'System.Core'. Using assembly 'EricsConnections_32' for assembly-level attributes for the target assembly. Merging assembly 'EricsConnections_32' into target assembly. Merging assembly 'ChilkatDotNet45' into target assembly. Assembly level attribute 'System.Security.AllowPartiallyTrustedCallersAttribute' from assembly 'ChilkatDotNet45' being deleted from target assembly Copying 8 Win32 Resources from assembly 'EricsConnections_32' into target assembly. There were no errors reported in the target assembly's metadata. ILMerge: Writing target assembly 'ericsconnectionsM.dll'. AssemblyResolver: Assembly 'System' is referencing assembly 'System.Configuration'. AssemblyResolver: Attempting referencing assembly's directory. Can not find PDB file. Debug info will not be available for assembly 'System.Configuration'. Resolved assembly reference 'System.Configuration' to 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Configuration.dll'. (Used referencing Module's directory.) Location for referenced module 'KERNEL32.dll' is '' Location for referenced module '' is '' Location for referenced assembly 'mscorlib' is 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll' There were no errors reported in mscorlib's metadata. Location for referenced assembly 'Microsoft.VisualBasic' is 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.VisualBasic.dll' There were no errors reported in Microsoft.VisualBasic's metadata. Location for referenced assembly 'System.Xml.Linq' is 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Xml.Linq.dll' There were no errors reported in System.Xml.Linq's metadata. Location for referenced assembly 'System.Core' is 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Core.dll' There were no errors reported in System.Core's metadata. Location for referenced assembly 'System.Data' is 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Data.dll' There were no errors reported in System.Data's metadata. Location for referenced assembly 'System' is 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\system.dll' There were no errors reported in System's metadata. ILMerge: Done.

What is going wrong?

2

2 Answers

3
votes

From the company's web site:

The Chilkat.NET components are written in Managed Visual C++

Better known by its proper name, C++/CLI. Which creates mixed-mode assemblies, they cannot be merged. ILMerge doesn't know how to properly handle the unmanaged code in such an assembly. Also notable is that your /targetplatform command line argument is wrong, it induces this failure mode.

2
votes

I gave up on ILmerge. Try Costura.Fody. Just install the nugget package (if using the Packet Manager Install-Package Costura.Fody will do the trick). And That's it.

Next time you build, your resulting .exe will have all the references merged as resources, and will automatically load them. Your output dir will still contain the referenced DLL's but your app will work without them.

Since you appear to be using unnmanaged libraries, you may have to set some options in the FodyWeavers.xml file (it will be added to your project when you install the nugget package). Quoting the project's documentation:

Mixed-mode assemblies cannot be loaded the same way as managed assemblies.

Therefore, to help Costura identify which assemblies are mixed-mode, and in what environment to load them in you should include their names in one or both of these lists.

Do not include .exe or .dll in the names.

<Costura>
    <Unmanaged32Assemblies>
        Foo32
        Bar32
    </Unmanaged32Assemblies>
    <Unmanaged64Assemblies>
        Foo64
        Bar64
    </Unmanaged64Assemblies>
</Costura>

Be sure to check the project page for other use cases.