gluck / il-repack

Open-source alternative to ILMerge
Apache License 2.0
1.16k stars 214 forks source link

Replacement for AllowDuplicateType Method of ILMerge #360

Closed sk185828 closed 4 months ago

sk185828 commented 5 months ago

There was a method with ILMerge which used to take typeName in string format as a input to allow those type of assemblies to be duplicated . The syntax is given below

public void AllowDuplicateType(string typeName);

KirillOsenkov commented 5 months ago

do you have a small example perhaps or a unit-test?

sk185828 commented 5 months ago

This is the code snippet which was written with ILMerge now I am trying to do the same with ILRepack . Here you will be able to see the method ILMerge.AllowDuplicateType

        var mainAssemblyName = args[0].ToLower();
        var assemblyBinFolder = args[1];
        var finalBinFolder = args[2];
        var specifiedVersion = "/v40";
        var allowDup = false;
        List<string> duplicateTypeList = null;

        if (args.Length > 3)
        {
            if (args[3].ToLower().StartsWith("/v4"))
            {
                specifiedVersion = args[3];
            }

            var arg = args.Skip(3).FirstOrDefault(s => s.ToLower().StartsWith("/allowdup"));
            if (arg != null)
            {
                allowDup = true;
                var s = arg.Split(':');
                if (s.Length > 1)
                {
                    duplicateTypeList = s[1].Split(',').ToList();
                }
            }
        }

       ilmerge.FileAlignment = 512;
        ilmerge.OutputFile = Path.Combine(finalBinFolder, mainAssemblyName);
        ilmerge.SetInputAssemblies(properInputAssemblies);

        if (allowDup)
        {
            if (duplicateTypeList == null)
            {
                ilmerge.AllowDuplicateType(null);
            }
            else
            {
                duplicateTypeList.ForEach(ilmerge.AllowDuplicateType);
            }
        }

        ilmerge.Log = true;
        ilmerge.Merge();
KirillOsenkov commented 5 months ago

ILRepack already supports both the /allowdup command-line arguments: image

I just made AllowDuplicateType public: https://github.com/gluck/il-repack/commit/bc568451f0ca360ab7cea57caca4877db77e305f

I also made AllowAllDuplicateTypes settable: https://github.com/gluck/il-repack/commit/79d83e6a3ed3551f466aff69153061c0246afb75

But even today you can do this:

image