The Dotfuscator Command Line Interface (CLI) allows you to run Dotfuscator from a command prompt, terminal, script, or automated process.
The CLI uses the same Dotfuscator configuration files used by other Dotfuscator interfaces and provides a flexible way to integrate protection into custom workflows.
When to Use the Command Line Interface
Use the Command Line Interface if you:
- Prefer command-line tools.
- Automate builds using scripts.
- Use custom build systems.
- Run protection in containers or automated environments.
- Need a platform-independent way to execute Dotfuscator.
How the Command Line Interface Works
The CLI executes Dotfuscator using a configuration file that defines the protection settings for your application.
The CLI reads the configuration, applies the configured protection features, and produces protected output and reports.
Because the CLI uses the same configuration format as other Dotfuscator interfaces, configurations can be created using the Config Editor and later executed from the command line.
Basic Workflow
To protect an application using the CLI:
-
Create a config file. You can use the Config Editor to accomplish this, or create a file manually. The following is a config file (
myconfig.xml) that enables renaming with an output mapping file.<?xml version="1.0"?> <!DOCTYPE dotfuscator SYSTEM "http://www.preemptive.com/dotfuscator/dtd/dotfuscator_v2.2.dtd"> <dotfuscator version="2.2"> <renaming> <mapping> <mapoutput overwrite="true"> <file dir="${configdir}/reports" name="MyMap.xml"/> </mapoutput> </mapping> </renaming> </dotfuscator> -
Open the command line interface. The way you call the command line differs depending on how you install Dotfuscator.
Windows installerIf you install with the Windows installer, the command line interface runs on .NET Framework. You can run it like any normal Windows console app:
"%DOTFUSCATOR_HOME%\dotfuscator.exe" path\to\your\DotfuscatorConfig.xmlSince the installer places the DOTFUSCATOR_HOME directory on the PATH, you can also just run the CLI by name:
dotfuscator path\to\your\DotfuscatorConfig.xml
NuGet packageIf you install with the NuGet package, the command line interface runs on .NET 6 or later. To run it, use the dotnet command:
dotnet {installation directory dir}/tools/programdir/netcore/dotfuscator.dll path\to\your\DotfuscatorConfig.xmlor use one of the provided scripts:
{installation dirrectory}/tools/programdir/netcore/dotfuscator path\to\your\DotfuscatorConfig.xml - Run a Dotfuscator build indicating the input assembly you want to obfuscate and the path to the config file as an argument to the CLI.
dotfuscator -in:my.dll config.xml
This command specifies my.dll as an input assembly in library mode (because of the DLL extension), and applies the renaming options in the config file. In this case, control flow, string encryption, and removal are disabled because they are implicitly disabled in the config file. - Review the generated reports and protected output. The output DLL goes in the "./Dotfuscated" directory, since an output is not specified in the config file or on the command line.
Creating a Config File from the CLI
Once you have the command line settings that you want for your application, you can save a config file containing those settings by using the -genconfig option. This takes all your command line options, merges them with your configuration template if you have one, and saves a custom config file that you can use for future runs.
Example:
dotfuscator -in:my.dll -keep:namespace -enha:on -cont:high -genconfig:new.xml myconfig.xmlThe resulting config file (new.xml) shows the command line options merged with the options from the original configuration (myconfig.xml):
Config File:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE dotfuscator SYSTEM "http://www.preemptive.com/dotfuscator/dtd/dotfuscator_v2.2.dtd">
<dotfuscator version="2.2">
<input>
<asmlist>
<inputassembly>
<option>library</option>
<file dir="." name="my.dll" />
</inputassembly>
</asmlist>
</input>
<output>
<file dir="${configdir}/Dotfuscated" />
</output>
<renaming>
<option>enhancedOI</option>
<option>keepnamespace</option>
<mapping>
<mapoutput overwrite="true">
<file dir="${configdir}/reports" name="MyMap.xml" />
</mapoutput>
</mapping>
</renaming>
<controlflow level="high" />
</dotfuscator>