How to modify csproj to automatically run obfuscar on relase build

2.6k Views Asked by At

I'm using Sharp Develop to create a c# project, which in turn creates a csproj file. Then, I installed obfuscar as follows:

From PowerShell as Administator:

PS> Install-Package Obfuscar

This places the Obfuscar.Console.exe executable in the directory:

C:\Program Files\PackageManagement\NuGet\Packages\Obfuscar.2.2.9\tools

Then I created the Obfuscar project file as follows:

FILE: obfuscar.xml:

<?xml version='1.0'?>
<Obfuscator>
  <Var name="InPath" value=".\bin\Release" />
  <Var name="OutPath" value=".\bin\Obfuscar" />
  <Module file="$(InPath)\BasicExemple.exe" />
</Obfuscator>

Now I'm wondering, how to modify my csproj such that when selecting a RELEASE build, it automatically creates the directory:

.\bin\Obfuscar

And run the the command on the exe under Release and places it in the ".\bin\Obfuscar" directory.

Obfuscar.Console.exe  obfuscar.xml

Would be nice if I can get Obfuscar to work like Eazfuscator where you just give it your csproj file then it automatically modifies the project to run the obfuscator upon selecting RELEASE build. Because, I think this flow would work in both Sharp Develop and Visual Studio.

If I look at how EazFuscator sets up my project file. Its does something like this:

<PropertyGroup>
    <PostBuildEvent>
        if /I "$(ConfigurationName)" == "Release" Eazfuscator.NET.exe "$(TargetPath)" --msbuild-project-path "$(ProjectPath)" --msbuild-project-configuration "$(ConfigurationName)" --msbuild-project-platform "$(PlatformName)" --msbuild-solution-path "$(SolutionPath)" -n --newline-flush -v 5.7
    </PostBuildEvent>
</PropertyGroup>

For instance. How to automatically lookup Obfuscar.console.exe install directory automatically in the msbuild project file (csproj), create the output directory, invoke the obfuscar command with the correct path the obsfuscar.console.exe, etc. Keep in mind, i'm setting this up for MSBuild from Sharp Develop, not for Visual Studio.

0

There are 0 best solutions below