Help us improve Softanics
We use analytics cookies to understand which pages and downloads are useful. No ads. Privacy Policy

MSBuild Obfuscation Task

It is quite easy to integrate obfuscation to a build process with the help of the MSBuild obfuscation task, that is implemented by the NuGet package: https://www.nuget.org/packages/ArmDot.Engine.MSBuildTasks/

After adding the MSBuild obfuscation task to a project, you are to modify the project file to activate the task:

<Target Name="Protect" AfterTargets="AfterCompile" BeforeTargets="BeforePublish">
  <ItemGroup>
     <Assemblies Include="$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" />
  </ItemGroup>
  <ArmDot.Engine.MSBuildTasks.ObfuscateTask
    Inputs="@(Assemblies)"
    ReferencePaths="@(_ResolveAssemblyReferenceResolvedFiles->'%(RootDir)%(Directory)')"
    SkipAlreadyObfuscatedAssemblies="true"
  />
</Target>

Often a release build is the only one to be obfuscated. To enable obfuscation for the release build only, use MSBuild condition:

<Target Name="Protect" AfterTargets="AfterCompile" BeforeTargets="BeforePublish"
  Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <ItemGroup>
     <Assemblies Include="$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" />
  </ItemGroup>
  <ArmDot.Engine.MSBuildTasks.ObfuscateTask
    Inputs="@(Assemblies)"
    ReferencePaths="@(_ResolveAssemblyReferenceResolvedFiles->'%(RootDir)%(Directory)')"
    SkipAlreadyObfuscatedAssemblies="true"
  />
</Target>