Command Line Interface
Here we explain how to use Dotfuscator's command line interface (CLI). For a complete reference on the available options see the Command Line Reference page.
The command line interface is designed to allow you to:
- Run a Dotfuscator build with an existing config file, for example on a build server.
- Protect your application without requiring creation of a config file.
- Override or supplement options in an existing config file.
- Create a config file.
Calling the Command Line
The way you call the command line differs depending on how you installed Dotfuscator.
If you installed 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
Since the installer places the
DOTFUSCATOR_HOME
directory on thePATH
, you can also just run the CLI by name:dotfuscator
If you installed with the NuGet package, the command line interface runs on .NET Core 2.1 or later. To run it, use the
dotnet
command:dotnet {install dir}/tools/programdir/netcore/dotfuscator.dll
or use one of the provided scripts:
{install dir}/tools/programdir/netcore/dotfuscator
where
{install dir}
is the installation directory you noted when provisioning the NuGet package.
The remainder of this page will just use dotfuscator
to indicate an invocation of the CLI.
Building from the Command Line
The primary use for the Dotfuscator command line program is running a Dotfuscator build when you already have a config file. To do so, provide the path to the config file as an argument to the CLI:
dotfuscator config.xml
Saving a Config File from the Command Line
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.xml
The 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>
Examples
The following examples use this config file that enables renaming with an output mapping file.
It is referenced as myconfig.xml
in the examples.
Example 1:
<?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>dotfuscator -in:my.dll myconfig.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.
The output DLL will go in a directory called ".\Dotfuscated", since an output is not specified in the config file or on the command line.
Example 2:
dotfuscator -in:my.dll -keep:namespace -enha:on -cont:high myconfig.xml
This command also specifies my.dll
as an input assembly.
In addition, it tells the renamer to keep namespaces and use enhanced overload induction.
It also enables control flow obfuscation, setting the level to "high" for maximum obfuscation.