0
votes

searching for a tool to merge .NET assemblies I always endup in trying ILMerge. But I don't get it working. Now I tried just a very simple example that doesn't work.

My library containing only this interface:

namespace CommonLib
{
    public interface IPlugin
    {
        string Name { get; }
        string Version { get; }
        void Load();
    }
}

My console application contains the class:

using System;
using CommonLib;

namespace ILMergeTest
{
    internal class DirectTestPlugin : IPlugin
    {
        public string Name => "DirectTestPlugin";
        public string Version => "4711.0.8.15";
        public void Load()
        {
            Console.WriteLine("Loading Plugin: " + Name + " [Version " + Version + "]");
        }
    }
}

and the Program.cs

using System;

namespace ILMergeTest
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var plugin = new DirectTestPlugin();
            plugin.Load();
            Console.ReadKey();
        }
    }
}

After compiling the application everything works fine.

Now I copy ILMerge.exe to the output directory, where my binaries are and create the following batch to perform ILMerge

mkdir Merged

ilmerge /union /ndebug /t:exe /copyattrs /closed /out:Merged\MergedProgram.exe /targetplatform:v4,"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1" "ILMergeTest.exe" "CommonLib.dll"
pause

My projects target Framework is .NET 4.6.1.

I always get the following error:

ILMerge.Merge: The assembly 'CommonLib' was not merged in correctly. It is still listed as an external reference in the target assembly.
bei ILMerging.ILMerge.Merge() bei ILMerging.ILMerge.Main(String[] args)

How do I fix this? The documentation of ILMerge didn't help me at all.

Thanks

1
What is your ultimate aim? Doing this seems to defeat the point of an shared-interface-plugin systemAlex K.
ILMerge is open source at GitHub, so when documentation is not enough, check its source code, github.com/microsoft/ilmergeLex Li
@Alex K.: the ultimate aim is to merge several dlls. With this simple testproject I will understand where/why ILMerge always ends in an error. In this simple test I will just embed the dll to the executable. Later in my real project I will ship only one dll as plugin.WPFGermany

1 Answers

1
votes

Now I got my fault! Using the /union causes this error in my case.

Now I use the following commandline and everything works as expected:

mkdir Merged
ilmerge /ndebug /t:exe /copyattrs /closed /out:Merged\MergedProgram.exe /targetplatform:v4,"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1" "ILMergeTest.exe" "CommonLib.dll"
pause