简体   繁体   中英

Renaming type from merged library

In main library there is a namespace Main.TargetNamespace . In merged library there is a public type Merged.SourceNamespace.Type .

I need to move the type Merged.SourceNamespace.Type to Main.TargetNamespace as public .

I did

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

But only internalization is disabled (ie the first line works): the type Merged.SourceNamespace.Type is public and available in obfuscated assembly.

How can I keep type Merged.SourceNamespace.Type from merged library public and move it to a specified namespace Main.TargetNamespace.Type ?

In order to keep Merged.SourceNamespace.Type public, it should be excluded from internalization:

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

The corresponding obfuscation settings of Main assembly should look like this:

[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 A general piece of advice. While the given recipe allows to achieve the goal, I would strongly suggest to avoid using it in production scenarios. Here is why: the public API of an assembly should be exclusively defined by the source code. Do not rely on a tool such as Eazfuscator.NET to do the API transform for you. Otherwise things quickly become hairy. For example, your colleague or future you may have hard times trying to figure out what's going on with that API and why on earth it depends on obfuscation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM