MSBuild Reference
To learn more about using Dotfuscator with MSBuild see the MSBuild Interface page.
Install Location
Dotfuscator's MSBuild components can be found in the following directories, based on the installation package you used:
Installation Package | Directory |
---|---|
Windows Installer | $(MSBuildProgramFiles32)\MSBuild\PreEmptive\Dotfuscator\7 |
NuGet Package | {install dir}/tools/msbuilddir |
where:
$(MSBuildProgramFiles32)
is a reserved MSBuild property pointing to theC:\Program Files (x86)
directory on 64-bit versions of Windows andC:\Program Files
on 32-bit versions.{install dir}
is the Dotfuscator installation directory you noted when installing the NuGet package.
Targets Reference
Dotfuscator's MSBuild targets, PreEmptive.Dotfuscator.Common.targets, make it easy to integrate Dotfuscator into a Visual Studio or MSBuild project. The targets are designed to run Dotfuscator immediately following the assembly build process, before packaging.
Available Properties
The following properties are understood by the Dotfuscator MSBuild Targets:
-
- Determines whether the Dotfuscator integration will run.
- If "true", Dotfuscator will protect the project.
- If "false", Dotfuscator will be skipped for this build.
- This property is available in the project file where the Dotfuscator MSBuild Targets are imported.
- This property defaults to "false".
- Determines whether the Dotfuscator integration will run.
-
- Path to the Dotfuscator config file, relative to the same directory as the MSBuild project file.
- This file does not need to exist if "DotfuscatorGenerateConfigFileIfMissing" is set to "true".
- This property is available in the project file where the Dotfuscator MSBuild Targets are imported.
- Defaults to "DotfuscatorConfig.xml".
DotfuscatorGenerateConfigFileIfMissing
- Determines what happens during a build if the file specified by "DotfuscatorConfigPath" does not exist.
- If "true", Dotfuscator generates a new config file at that path using relevant MSBuild properties.
- If "false", Dotfuscator errors the build.
- This property is available in the project file where the Dotfuscator MSBuild Targets are imported.
- This property defaults to "true".
- Determines what happens during a build if the file specified by "DotfuscatorConfigPath" does not exist.
DotfuscatorAndroidSigningCertFingerprint
- Specifies the SHA-1 fingerprint of the certificate used to sign the Xamarin Android App. If you are using key rotation and your application requires Android Pie (or later), use the last alias in the rotation, otherwise, you need to provide the first alias in the rotation.
- Only required when injecting Tamper Check into a Xamarin Android app.
- This property is available in any Xamarin.Android project file where the Dotfuscator MSBuild Targets are imported.
- This property is not set by default.
-
- Specifies a Dotfuscator license string to activate and use for this run of Dotfuscator. Typically this will be done with a Floating License.
- The value of this property will be used even if another license is also specified through an environment variable or in the license file.
- This property is available in the project file where the Dotfuscator MSBuild Targets are imported.
- This property is not set by default.
-
- Specifies whether the current project's assembly should be protected by Dotfuscator when Dotfuscator is integrated into another project which references this project. For more information, see Controlling Which Assemblies are Protected.
- This property is available in project files referenced, directly or indirectly, by the project where the Dotfuscator MSBuild Targets are imported.
- The property is not available in the project where the Dotfuscator MSBuild Targets are imported.
- This property defaults to
true
.
Available Item Metadata
The following metadata are understood by the Dotfuscator MSBuild Targets:
- DotfuscatorIncludeAsInput
- Specifies whether an external referenced assembly should be included as an input to Dotfuscator. For more information, see Controlling Which Assemblies Are Protected.
- This metadata is available on
Reference
items in any project file in your solution, including the project where the Dotfuscator MSBuild Targets are imported. Dotfuscator will error if it is set onProjectReference
orPackageReference
items, as this setting is not supported on those kinds of references. - This metadata defaults to
false
.
MSBuild Task Reference
Dotfuscator provides an MSBuild interface through two task libraries.
Legacy Library:
legacy/PreEmptive.Dotfuscator.Tasks.dll
Modern Library:
PreEmptive.Dotfuscator.Tasks.dll
The two libraries contain the same task definitions but target different sets of MSBuild flavors and versions. The table below summarizes what MSBuild installations support each version.
MSBuild Flavor | MSBuild Version | Legacy Library | Modern Library |
---|---|---|---|
.NET Framework | 4 - 14 | ✅ | ❌ |
.NET Framework | 15 + | ✅ | ✅ |
.NET Core | 16 + | ❌ | ✅ |
Mono | 16 + | ❌ | ✅ |
Dotfuscate Task
You can run Dotfuscator from MSBuild using the Dotfuscate task. Below are the properties provided by the Dotfuscate task.
Property | Type | Direction | Description |
---|---|---|---|
ConfigPath |
string |
Input | Required. Sets the path to the Dotfuscator config. |
DebugSymbols |
string[] |
Output | Exposes PDB files associated with output assemblies. The PreEmptive.Dotfuscator.targets file exposes this property as an output Item named DotfuscatedDebugSymbols |
InputAssemblies |
ITaskItem[] |
Input | Sets the input assemblies. Inputs specified in InputAssemblies are merged with the inputs listed in the Dotfuscator config. |
InputManagement |
string |
Input | Sets how the Dotfuscate task uses inputs. If automatic Dotfuscator gets inputs only from the InputAssemblies property and updates the inputs in the config to match. If manual or unspecified, Dotfuscator will merge the inputs specified in InputAssemblies and specified in the config. |
License |
string |
Input | Specifies a Dotfuscator license string to activate and use for this run of Dotfuscator. Typically this property is used for a Floating License. The value of this property will be used even if another license is specified by an environment variable or in the license file. |
MappingFile |
string |
Output | Exposes the renaming map file. The PreEmptive.Dotfuscator.targets file exposes this property as an output Item named DotfuscatorMappingFile. |
OutputAssemblies |
string[] |
Output | Exposes output assemblies. The PreEmptive.Dotfuscator.targets file exposes this property as an output Item named DotfuscatedAssemblies. |
OutputDirectory |
string |
Input | Sets the directory where Dotfuscator will write the output assemblies. This overrides the output directory specified in the Dotfuscator config. |
Properties |
string |
Input | Sets user-defined external properties. The string should consist of XML elements, with the name and element value mapped to the property name and value respectively. For example: <Property1>Value1</Property1><Property2>2</Property2> The use of XML elements allows the properties to be defined intuitively in MSBuild project files as MSBuild properties like so: <PropertyGroup> <MyDotfuscatorProperties> <Property1>Value1</Property1> <Property2>2</Property2> </MyDotfuscatorProperties> </PropertyGroup> You can then pass $(MyDotfuscatorProperties) to this property |
ReportFiles |
string[] |
Output | Exposes report files such as renaming HTML report and removal reports. |
SatelliteAssemblies |
string[] |
Output | Exposes satellite assemblies associated with output assemblies. The PreEmptive.Dotfuscator.targets file exposes this property as an output Item named DotfuscatedSatelliteAssemblies. |