从合并库中重命名类型

Renaming type from merged library

在主库中有一个命名空间 Main.TargetNamespace。在合并库中有一个 public 类型 Merged.SourceNamespace.Type

我需要将类型 Merged.SourceNamespace.Type 移动到 Main.TargetNamespace 作为 public

我做到了

[assembly: Obfuscation(Feature = "ilmerge custom parameters: /internalize:exclude.file", Exclude = false)]
[assembly: Obfuscation(Feature = "Apply to type Merged.SourceNamespace.Type: type renaming pattern Main.TargetNamespace.Type", Exclude = false)]

但只有内部化被禁用(即第一行有效):类型 Merged.SourceNamespace.Type 是 public 并且在混淆汇编中可用。

如何从合并的库 public 中保留类型 Merged.SourceNamespace.Type 并将其移动到指定的命名空间 Main.TargetNamespace.Type

为了保持Merged.SourceNamespace.Typepublic,应该排除内化:

namespace Merged.SourceNamespace
{
    [Obfuscation(Feature = "internalization", Exclude = true)]
    public class Type
    {
        // ...
    }
}

Main程序集对应的混淆设置应该是这样的:

[assembly: Obfuscation(Feature = "merge with Merged.dll", Exclude = false)]
[assembly: Obfuscation(Feature = "Apply to type Merged.SourceNamespace.Type: type renaming pattern Main.TargetNamespace.Type", Exclude = false)]

P.S。一般的建议。虽然给定的配方可以实现目标,但我强烈建议避免在生产场景中使用它。原因如下:程序集的 public API 应该由源代码专门定义。不要依赖 Eazfuscator.NET 等工具为您执行 API 转换。否则事情很快就会变得多毛。例如,您的同事或未来的您可能很难弄清楚那个 API 到底发生了什么,以及为什么它依赖于混淆。