This is an MSBuild custom task that can be triggered at any event after compilation to automatically obfuscate assembly files.
.NET CLI:
dotnet add package Obfuscation.Tasks --version 1.0.2
or PowerShell:
Install-Package Obfuscation.Tasks -Version 1.0.2
or Edit project items:
<ItemGroup>
<PackageReference Include="Obfuscation.Tasks" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
Triggered after PostBuildEvent
:
<Target Name="Obfuscation" AfterTargets="PostBuildEvent">
<ObfuscationTask ToolDir="\\192.168.1.155\dll" InputFilePaths="$(TargetPath)" DependencyFiles="" OutputFileNameSuffix="" TimeoutMillisecond="2000" Importance="high">
<Output TaskParameter="OutputFilePaths" PropertyName="SecuredFilePaths" />
</ObfuscationTask>
<Message Text="SecuredFilePaths: $(SecuredFilePaths)" Importance="high" />
</Target>
Or trigger after publication.
Here's a detail, when the OutputType
is Library
, it needs to depend on the GenerateNuspec
target.
When the OutputType
is Exe
, it needs to depend on the Publish
target.
<Target Name="Obfuscation" AfterTargets="GenerateNuspec">
<ObfuscationTask ToolDir="\\192.168.1.155\dll" InputFilePaths="$(TargetPath)" Importance="low">
<Output TaskParameter="OutputFilePaths" PropertyName="SecuredFilePaths" />
</ObfuscationTask>
<Message Text="SecuredFilePaths: $(SecuredFilePaths)" Importance="high" />
</Target>
-
Input Parameters:
ToolDir
: Required. Example:\\192.168.1.155\dll
InputFilePaths
: Required. Single example:D:\sources\ObfuscationSamples\ObfuscationSamples\bin\Release\ObfuscationSamples.dll
; Multiple examples:$(TargetPath);D:\ref\Samples1.dll;D:\ref\Samples2.dll
DependencyFiles
: Optional. Example:$(OutputPath)Serilog.dll;$(OutputPath)Serilog.Sinks.Console.dll
TimeoutMillisecond
: Optional. Default value:30000
Importance
: Optional. Default value: Normal. Options:High
,Normal
,Low
. ReferenceMessage
taskOutputFileNameSuffix
: Optional. Default value:_Secure
-
Output Parameters:
OutputFilePaths
: string. Default value:$(InputFilePaths)$(OutputFileNameSuffix).dll
. Example:D:\sources\ObfuscationSamples\ObfuscationSamples\bin\Release\ObfuscationSamples_Secure.dll
Support MSBuild v15.0 or higher.