Is it possible to only merge a subset of dependencies using ILMerge?

后端 未结 3 2152
广开言路
广开言路 2021-01-04 10:28

I\'m trying something exploratory:

Say I have a library \"coolproject\" and it has dependencies to one.dll, two.dll, and three.dll

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-04 11:04

    I think you're looking for the 'exclude' parameter for the /internalize switch. For example, if you use

    /internalize:excludes.txt
    

    where the file excludes.txt contains

    three.dll
    

    it will internalize one.dll and two.dll but leave three.dll as an external dependancy.

    Here are a couple of blog posts that go into further detail:

    • http://www.bjoernrochel.de/2009/07/07/how-to-shoot-yourself-in-the-foot-with-ilmerge/
    • http://www.blackwasp.co.uk/ILMergeInternalize.aspx

    Update: From the documentation:

    2.10 ExcludeFile

    public string ExcludeFile { get; set; }

    This property is used only in conjunction with the Internalize property (Section 2.12). When this is set before calling Merge, it indicates the path and filename that will be used to identify types that are not to have their visibility modified. If Internalize is true, but ExcludeFile is "", then all types in any assembly other than the primary assembly are made non-public. Setting this property implicitly sets Internalize to true.

    The contents of the file should be one regular expression per line. The syntax is that defined in the .NET namespace System.Text.RegularExpressions for regular expressions. The regular expressions are matched against each type's full name, e.g., "System.Collections.IList". If the match fails, it is tried again with the assembly name (surrounded by square brackets) prepended to the type name. Thus, the pattern “[A].*” excludes all types in assembly A from being made non-public. (The backslashes are required because the string is treated as a regular expression.) The pattern “N.T” will match all types named T in the namespace named N no matter what assembly they are defined in.

    It is important to note that the regular expressions are not anchored to the beginning of the string; if this is desired, use the appropriate regular expression operator characters to do so.

    2.12 Internalize

    public bool Internalize { get; set; }

    This controls whether types in assemblies other than the primary assembly have their visibility modified. When it is true, then all non-exempt types that are visible outside of their assembly have their visibility modified so that they are not visible from outside of the merged assembly. A type is exempt if its full name matches a line from the ExcludeFile (Section 2.10) using the .NET regular expression engine.

提交回复
热议问题