0

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

我需要将类型移动Merged.SourceNamespace.TypeMain.TargetNamespaceas 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是公共的并且在混淆程序集中可用。

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

4

1 回答 1

1

为了保持Merged.SourceNamespace.Type公开,应将其排除在内部化之外:

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)]

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

于 2018-01-15T21:02:27.083 回答