Class ObfuscateTask
This is an MSBuild task to automate obfuscation using ArmDot.
Read more about how to use ObfuscateTask
to obfuscate assemblies while building a project.
Inherited Members
Namespace: ArmDot.Engine.MSBuildTasks
Assembly: ArmDot.Engine.MSBuildTasks.dll
Syntax
public class ObfuscateTask : Task, ITask, IAsyncOperationEvents
Properties
EmbeddedFiles
This parameter is optional.
EmbeddedFiles
stores a list of files to embed.
Notes: use %24
to encode $
For example, use %24(AssemblyDirectory)
to encode $(AssemblyDirectory)
<ItemGroup>
<FilesInfo Include="$(TargetDir)Embed\virtual_file_content2.txt">
<RuntimePath>%24(AssemblyDirectory)\embedded_file2.txt</RuntimePath>
</FilesInfo>
<FilesInfo Include="$(TargetDir)Embed\virtual_file_content3.txt">
<RuntimePath>%24(AssemblyDirectory)\embedded_file3.txt</RuntimePath>
</FilesInfo>
</ItemGroup>
<Target Name="Protect" AfterTargets="AfterCompile" BeforeTargets="BeforePublish">
<ItemGroup>
<Assemblies Include="$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" />
</ItemGroup>
<ArmDot.Engine.MSBuildTasks.ObfuscateTask
Inputs="@(Assemblies)"
EmbeddedFiles="@(FilesInfo)"
ReferencePaths="@(_ResolveAssemblyReferenceResolvedFiles->'%(RootDir)%(Directory)')"
SkipAlreadyObfuscatedAssemblies="true"
/>
</Target>
Declaration
public ITaskItem[] EmbeddedFiles { get; set; }
Property Value
Type | Description |
---|---|
ITaskItem[] |
Inputs
This parameter is required.
Inputs
stores a list of assemblies to protect:
<Target Name="Protect" AfterTargets="AfterCompile" BeforeTargets="BeforePublish">
<ItemGroup>
<Assemblies Include="$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" />
</ItemGroup>
<ArmDot.Engine.MSBuildTasks.ObfuscateTask
Inputs="@(Assemblies)"
ReferencePaths="@(_ResolveAssemblyReferenceResolvedFiles->'%(RootDir)%(Directory)')"
SkipAlreadyObfuscatedAssemblies="true"
/>
</Target>
Also, Inputs
can contain options for an assembly.
The following options are available:
KeyFile
specifies the path to the file containing the key pair, which is used to generate a strong name. If specified, ArmDot signs the assembly after obfuscation using the specified file. Use this option if an assembly is a strong-named one. Obfuscation modifies an assembly making a strong name signature not valid. That is why signing is required:
<Target Name="Protect" AfterTargets="AfterCompile" BeforeTargets="BeforePublish">
<ItemGroup>
<Assemblies
Include="$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)"
KeyFile="key.snk"
/>
</ItemGroup>
<ArmDot.Engine.MSBuildTasks.ObfuscateTask
Inputs="@(Assemblies)"
ReferencePaths="@(_ResolveAssemblyReferenceResolvedFiles->'%(RootDir)%(Directory)')"
SkipAlreadyObfuscatedAssemblies="true"
/>
</Target>
CreatePDB
instructs ArmDot whether to create a PDB file or not. The possible values are: true
, or false
.
Declaration
[Required]
public ITaskItem[] Inputs { get; set; }
Property Value
Type | Description |
---|---|
ITaskItem[] |
License
This parameter is deprecated.
Declaration
public string License { get; set; }
Property Value
Type | Description |
---|---|
string |
LicenseFile
This parameter is optional.
Set it to a file that stores a purchased ArmDot license key.
If LicenseFile
is not set, ArmDot tries to read a license key from the default location. If it fails, ArmDot works in the demo mode.
Declaration
public string LicenseFile { get; set; }
Property Value
Type | Description |
---|---|
string |
LogFile
This parameter is optional.
Set the LogFile
to the desired path for writing the log.
Declaration
public string LogFile { get; set; }
Property Value
Type | Description |
---|---|
string |
LogLevel
This parameter is optional.
Set the LogLevel
to the desired debug log level. The possible values are as follows: DEBUG
, INFO
, WARN
, ERROR
.
Declaration
public string LogLevel { get; set; }
Property Value
Type | Description |
---|---|
string |
MapFile
This parameter is optional.
This parameter tells ArmDot writes information about original and obfuscated names to the specified file.
Map files are used to deobfuscate stack traces.
Example:
<Target Name="Protect" AfterTargets="AfterCompile" BeforeTargets="BeforePublish">
<ItemGroup>
<Assemblies Include="$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" />
</ItemGroup>
<ArmDot.Engine.MSBuildTasks.ObfuscateTask
Inputs="@(Assemblies)"
MapFile="map.xml"
SkipAlreadyObfuscatedAssemblies="true"
/>
</Target>
Declaration
public string MapFile { get; set; }
Property Value
Type | Description |
---|---|
string |
NoWarn
This parameter is optional.
Suppresses the ArmDot's ability to generate warnings.
NoWarn
specifies warning number or numbers.
If you specify multiple warning numbers, separate them with a comma:
<Target Name="Protect" AfterTargets="AfterCompile" BeforeTargets="BeforePublish">
<ItemGroup>
<Assemblies Include="$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" />
</ItemGroup>
<ArmDot.Engine.MSBuildTasks.ObfuscateTask
Inputs="@(Assemblies)"
NoWarn="4"
ReferencePaths="@(_ResolveAssemblyReferenceResolvedFiles->'%(RootDir)%(Directory)')"
SkipAlreadyObfuscatedAssemblies="true"
/>
</Target>
Declaration
public string NoWarn { get; set; }
Property Value
Type | Description |
---|---|
string |
ProjectPath
This parameter is optional.
ProjectPath
specifies a path to a project file that is used to store cryptography constants to generate license keys, and blacklisted license keys.
If ProjectPath
doesn't exist, a new project file is created.
Declaration
public string ProjectPath { get; set; }
Property Value
Type | Description |
---|---|
string |
ReferencePaths
This parameter is optional.
ReferencePaths
stores a list of directories to find referenced assemblies.
Sometimes ArmDot needs to find an assembly referenced by the assembly which is being protected.
To help ArmDot locate such an assembly, use ReferencePaths
:
<Target Name="Protect" AfterTargets="AfterCompile" BeforeTargets="BeforePublish">
<ItemGroup>
<Assemblies Include="$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" />
</ItemGroup>
<ItemGroup>
<ReferencePaths Include="C:\MyAssemblies" />
<ReferencePaths Include="@(_ResolveAssemblyReferenceResolvedFiles->'%(RootDir)%(Directory)')" />
</ItemGroup>
<ArmDot.Engine.MSBuildTasks.ObfuscateTask
Inputs="@(Assemblies)"
ReferencePaths="@(ReferencePaths)"
SkipAlreadyObfuscatedAssemblies="true"
/>
</Target>
Declaration
public ITaskItem[] ReferencePaths { get; set; }
Property Value
Type | Description |
---|---|
ITaskItem[] |
SkipAlreadyObfuscatedAssemblies
This parameter is optional.
This parameter tells ArmDot not to obfuscate assemblies that are obfuscated already.
Declaration
public bool SkipAlreadyObfuscatedAssemblies { get; set; }
Property Value
Type | Description |
---|---|
bool |
TreatAllWarningsAsErrors
This parameter is optional.
This parameter tells ArmDot to treat all warnings as errors. Because an error occurred, no obfuscated assembly was generated:
<Target Name="Protect" AfterTargets="AfterCompile" BeforeTargets="BeforePublish">
<ItemGroup>
<Assemblies Include="$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" />
</ItemGroup>
<ArmDot.Engine.MSBuildTasks.ObfuscateTask
Inputs="@(Assemblies)"
TreatAllWarningsAsErrors="true"
ReferencePaths="@(_ResolveAssemblyReferenceResolvedFiles->'%(RootDir)%(Directory)')"
SkipAlreadyObfuscatedAssemblies="true"
/>
</Target>
Declaration
public bool TreatAllWarningsAsErrors { get; set; }
Property Value
Type | Description |
---|---|
bool |
Methods
Execute()
You never call this method.
Declaration
public override bool Execute()
Returns
Type | Description |
---|---|
bool |
Overrides
OnError(string)
You never call this method.
Declaration
public void OnError(string text)
Parameters
Type | Name | Description |
---|---|---|
string | text |
OnFinished(Exception)
You never call this method.
Declaration
public void OnFinished(Exception error)
Parameters
Type | Name | Description |
---|---|---|
Exception | error |
OnInfo(string)
You never call this method.
Declaration
public void OnInfo(string text)
Parameters
Type | Name | Description |
---|---|---|
string | text |
OnProgress(int)
You never call this method.
Declaration
public void OnProgress(int percent)
Parameters
Type | Name | Description |
---|---|---|
int | percent |
OnWarning(BaseWarning)
You never call this method.
Declaration
public void OnWarning(BaseWarning warning)
Parameters
Type | Name | Description |
---|---|---|
BaseWarning | warning |