How to use Dotfuscator in Visual Studio

This post shows you how to use Dotfuscator in visual studio 2017, 2019

Dotfuscator is a tool to prevent decompilation .net source code. Dotfuscator is a .NET Obfuscator, it helps protect your .net application.

How to use Dotfuscator in Visual Studio

Obfuscation is a technique that provides the ability to seamlessly rename the symbols in assemblies as well as other tricks to foil decompilers. Through this post you will learn how to use dotfuscator in visual studio 2017, 2019.

After completing the Dotfuscator installation, open your Visual Studio and select Tools =>PreEmptive Protection - Dotfuscator

dotfuscator community edition

Clicking Ok button.

dotfuscator community edition registration

Entering your information, then click Submit button.

dotfuscator download

Clicking Download Now button.

dotfuscator registration

Entering your confirmation code. You can find it in the email when completing registration.

Creating a new console application, then modify your code as shown below.

class Program
{
    static void Main(string[] args)
    {
        // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.
        int limit = 77;
        string connectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
        for (int i = 1; i <= limit; i++)
        {
            using (SqlConnection cn = new SqlConnection(connectionString))
            {
                if (cn.State == System.Data.ConnectionState.Closed)
                    cn.Open();
                using (SqlCommand cmd = new SqlCommand($"select ProductName from Products where ProductID={i}", cn))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                            Console.WriteLine(string.Format("{0}: {1}\n", i, reader.GetString(0)));
                    }
                }
            }
        }
        Console.ReadKey();
    }
}

Opening your App.config file, then add a connection string as shown below.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
  <connectionStrings>
    <add name="cn" connectionString="Data Source=.;Initial Catalog=Northwind;User ID=sa;Password=123@qaz;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>

You should modify your connection string based on your sql account and database. I'm using Northwind database to play demo.

The c# code above allows you to connect to sql server, then retrieve products data from the products table in your Northwind database.

Changing from Debug to Release mode, then rebuild your project.

Opening your Visual Studio and select Tools =>PreEmptive Protection - Dotfuscator

preemptive dotfuscator ce

Selecting Input item, then click Add button => Select your executable in the release directory => Click Build button.

c# dotfuscator

After completing the build, you will see detailed information below the screen

You will find the file ofuscator in the Dotfuscated folder located in the Release folder.

c# ofuscator

If you use the dnspy ​​tool to view the executable file, you might find that your file is decompiled.

dnspy

As you know, dnspy ​​is a free tool that allows you to view and decompile .net source code.