Tag Archives: dotfuscator

Protect your .net code – Integrate dotfuscator into you build process

In .net world, all code are compiled into MSIL, which means with some tool like .net reflector, the receiver of exe binary could decompile back almost exactly the same copy of your source code. Doing .net apps are same like doing open source apps. So obfuscater is crucial if you are not doing an open source project.

Microsoft Visual Studio already comes with an obfuscator, but it’s only in the GUI form, you have to run it everytime manually, but what we like is make it auto run during your build process, specifically, we want it run automatically during the build process of the installer.

Part I: Get the command line version of dotfuscator:

  1. Go to the site of dotfuscator here, and register.
  2. After register, login with your account and go to the download section here
  3. Read carefully, and you will see the text like:
    “For the ability to run CE from the commandline, click here to download the Dotfuscator CE5 Patch version 5.0.2601″
  4. Follow the guide and click in, it will require you provide more info to fill in another from in order to let you download the command line version of the obfuscator. Do it and you will get the file.
  5. Once you have it, install it.

Part 2: Integrate into your build process

We don’t want to run obfuscator everytime doing testing or debug, so the best way to use it is to run it during the build process of your installer.

  1. Open GUI version obfuscator, do it as normal: add your exe file, setup config detail and create a config file named: obfuscator.xml
  2. Embed this command line code into your post builder process or your build script:
    "D:\Program Files\Microsoft Visual Studio 10.0\PreEmptive Solutions\Dotfuscator Community Edition\dotfuscatorCLI.exe" /q obfuscator.xml

In my case, I use nsis to pack my setup files, I created a make.cmd to build the setup file, so I put it in make.cmd:

echo obfuscator
"D:\Program Files\Microsoft Visual Studio 10.0\PreEmptive Solutions\Dotfuscator Community Edition\dotfuscatorCLI.exe" /q obfuscator.xml

echo pack
"C:\Program Files\NSIS\Unicode\makensis.exe" setup.nsi

In case you are using traditional msi setup project comes with visual studio, click on the setup project, paste the code in PreBuildEvent in the Properties tab, and make sure the file path could be found, try to use absolute path if necessary, and do reference the obfuscated file in the setup script.