Dotfuscator supports declarative configuration through .NET attributes. By applying obfuscation attributes directly in your source code, you can configure protection behavior without modifying your Dotfuscator configuration file.
For an introduction to using attributes, including common workflows and examples, see Protect Your App Using .NET Attributes.
Referencing the Attributes
Dotfuscator recognizes obfuscation attributes defined in either the .NET Base Class Libraries or a Dotfuscator reference assembly.
Use the .NET Base Class Libraries
The obfuscation attributes are defined in:
| Library | Availability |
mscorlib.dll |
.NET Framework 2.0 and later |
netstandard.dll |
.NET Standard 2.0 and later |
Most .NET projects already reference one of these assemblies, so no additional setup is required.
Namespace: System.Reflection
Use the Dotfuscator Reference Assembly
If your target framework does not include the obfuscation attributes in System.Reflection, you can reference the Dotfuscator attribute assembly instead.
| Assembly | Namespace |
PreEmptive.ObfuscationAttributes.dll |
PreEmptive.Dotfuscator.ObfuscationAttributes |
The assembly is installed with Dotfuscator and can be found in the Dotfuscator installation directory.
To locate the assembly:
- Open a command prompt.
-
Run:
where PreEmptive.ObfuscationAttributes.dll - Add a reference to your project to the returned path.
Since the assembly has no dependencies besides the framework itself, you can copy it to a different location if required.
Supported Attributes
Dotfuscator recognizes the following attributes:
| Attribute | Purpose |
ObfuscationAttribute |
Configures Renaming, Control Flow, String Encryption, Removal, and other obfuscation features. |
ObfuscateAssemblyAttribute |
Specifies whether an assembly should be treated as a library assembly. |
ObfuscationAttribute
Use ObfuscationAttribute to configure protection behavior for an assembly, type, or member.
Each instance of the attribute specifies:
- The protection feature to configure.
- Whether the annotated element should be included or excluded from that feature.
Metadata
| Property | Value |
| Namespace |
System.Reflection or PreEmptive.Dotfuscator.ObfuscationAttributes
|
| Applies To | Assembly, type, or member |
| Multiple Allowed | Yes |
Requirements
Dotfuscator only processes the attribute when:
- Honor Obfuscation Attributes is enabled for the input assembly (enabled by default).
Dotfuscator removes the attribute from the protected assembly when either of the following is true:
- Strip Obfuscation Attributes is enabled for the input assembly (enabled by default), or
-
StripAfterObfuscationis set totrue.
Properties
Feature
Specifies the protection feature affected by the attribute.
| Value | Description |
all |
Alias for renaming. Default value. |
default |
Alias for renaming. |
renaming |
Configures Renaming exclusions. |
controlflow |
Configures Control Flow exclusions. |
stringencryption |
Configures String Encryption inclusions. |
trigger |
Configures Removal entry points. |
conditionalinclude |
Configures conditional Removal inclusions. |
| Config-specific feature map strings | Alias for one or more features defined in the configuration file. |
Exclude
Determines whether the annotated element is included in or excluded from the specified feature.
| Value | Behavior |
true |
Excludes the element from the feature. |
false |
Includes the element in the feature. |
Default value: true
Recommended values by feature:
| Feature | Exclude Value |
| Renaming | true |
| Control Flow | true |
| String Encryption | false |
| Removal Trigger | false |
| Conditional Removal Include | false |
Dotfuscator supports only one valid Exclude value for each feature. Unsupported values are ignored.
ApplyToMembers
When applied to a type, specifies whether the configuration also applies to the type's members and nested types.
| Value | Description |
true |
Apply to members and nested types. |
false |
Apply only to the annotated type. |
Default value: true
StripAfterObfuscation
Specifies whether Dotfuscator removes the attribute from the protected assembly.
| Value | Description |
true |
Remove the attribute after processing. |
false |
Preserve the attribute unless Strip Obfuscation Attributes is enabled. |
Default value: true
ObfuscateAssemblyAttribute
Use ObfuscateAssemblyAttribute to specify whether an assembly should be treated as a library assembly.
This attribute overrides the Library Mode input option.
Metadata
| Property | Value |
| Namespace |
System.Reflection or PreEmptive.Dotfuscator.ObfuscationAttributes
|
| Applies To | Assembly |
| Multiple Allowed | No |
Requirements
Dotfuscator only processes the attribute when:
- Honor Obfuscation Attributes is enabled for the input assembly (enabled by default).
Dotfuscator removes the attribute from the protected assembly when either:
- Strip Obfuscation Attributes is enabled, or
-
StripAfterObfuscationis set totrue.
Properties
AssemblyIsPrivate
Specifies whether Dotfuscator should treat the assembly as a library.
| Value | Behavior |
true |
Treat the assembly as a non-library assembly and apply more aggressive protection. |
false |
Treat the assembly as a library assembly and preserve the public contract. |
Default value: false
StripAfterObfuscation
Specifies whether Dotfuscator removes the attribute from the protected assembly.
| Value | Description |
true |
Remove the attribute after processing. |
false |
Preserve the attribute unless Strip Obfuscation Attributes is enabled. |
Default value: true
Related Articles
- Protect Your App Using .NET Attributes
- Obfuscate Your Code With Renaming
- Obfuscate Your Code With Control Flow