Integrating ConfuserEx in MsBuild

1k Views Asked by At

I am trying to integrate ConfuserEx version 1.6 in MsBuild. It suppose to obfuscate the files automatically but it's not working for me. I have added Confuser.MsBuild v1.6 nuget package to the project.

Can somebody help me if I am missing any step.

1

There are 1 best solutions below

0
Fruchtzwerg On

After adding the Confuser.MsBuild nuget to your project the following lines should be added automatically to your *.csproj file:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  <PropertyGroup>
    <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
  </PropertyGroup>
  <Error Condition="!Exists('..\packages\Confuser.MSBuild.1.6.0\build\Confuser.MSBuild.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Confuser.MSBuild.1.6.0\build\Confuser.MSBuild.targets'))" />
</Target>
<Import Project="..\packages\Confuser.MSBuild.1.6.0\build\Confuser.MSBuild.targets" Condition="Exists('..\packages\Confuser.MSBuild.1.6.0\build\Confuser.MSBuild.targets')" />

Now you are able to include the obfuscation to the build process. This is also done in the *.csproj file with a minimal entry like:

<PropertyGroup>
  <Obfuscate>true</Obfuscate>
  <ConfuserReplaceOutput>true</ConfuserReplaceOutput>
</PropertyGroup>

Fore more and detailed information and options check out the ConfuserEx wiki.