ricaun.Obfuscar
1.3.0
Prefix Reserved
dotnet add package ricaun.Obfuscar --version 1.3.0
NuGet\Install-Package ricaun.Obfuscar -Version 1.3.0
<PackageReference Include="ricaun.Obfuscar" Version="1.3.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="ricaun.Obfuscar" Version="1.3.0" />
<PackageReference Include="ricaun.Obfuscar"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add ricaun.Obfuscar --version 1.3.0
#r "nuget: ricaun.Obfuscar, 1.3.0"
#:package ricaun.Obfuscar@1.3.0
#addin nuget:?package=ricaun.Obfuscar&version=1.3.0
#tool nuget:?package=ricaun.Obfuscar&version=1.3.0
ricaun.Obfuscar
ricaun.Obfuscar is a basic obfuscator for .NET assemblies. Uses the package Obfuscar to obfucate the assembly using Target to replate the original dll to the obfuscate dll.
By default the obfuscar target execute before CopyFilesToOutputDirectory to replace the IntermediateAssembly file.
Installation
Install the package using the NuGet package manager or using PackageReference.
<PackageReference Include="ricaun.Obfuscar" Version="*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
By default the obfuscar is enabled when the package is used, and the KeepPublicApi, HidePrivateApi, AnalyzeXaml and SkipGenerated options are set to true.
Is possible to use the [System.Reflection.Obfuscation] to disable the obfuscation in some classes.
Version
The package Obfuscar with version 2.2.50 is used by default to repack the assembly, if the your project contains a different version, the package will use the version from the package.
<PackageReference Include="Obfuscar" Version="*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Configuration
PropertyGroups
| Property Name | Default Value | Description |
|---|---|---|
ObfuscarEnabled |
true |
Enable / Disable Obfuscar task. |
ObfuscarFileName |
obfuscar.xml |
Obfuscar configuration file name. |
ObfuscarFolderName |
Obfuscar |
Obfuscar folder to release obfuscar files. |
ObfuscarConfiguration |
See below | Default configuration in the obfuscar.xml file. |
ObfuscarContent |
Extra configuration to add in the obfuscar.xml file. | |
ObfuscarContentModule |
Extra configuration to add inside the module in the obfuscar.xml file. | |
ObfuscarPathReferencesEnabled |
true |
Add the references folder to the ObfuscarPathReferences to search path in the obfuscar.xml file. |
ObfuscarImportance |
High |
Log importance to show the main obfuscar. (Low or High) |
ObfuscarCopyImportance |
Low |
Log importance to show in the console. (Low or High) |
ObfuscarCommandImportance |
Low |
Log importance from the Obfuscar.exe to show in the console. (Low or High) |
ObfuscarAfterTargets |
Target to run obfuscation after. | |
ObfuscarBeforeTargets |
CopyFilesToOutputDirectory |
Target to run obfuscation before. |
<PropertyGroup>
<ObfuscarEnabled>true</ObfuscarEnabled>
<ObfuscarFileName>obfuscar.xml</ObfuscarFileName>
<ObfuscarFolderName>Obfuscar</ObfuscarFolderName>
<ObfuscarContent></ObfuscarContent>
<ObfuscarPathReferencesEnabled>true</ObfuscarPathReferencesEnabled>
<ObfuscarImportance>High</ObfuscarImportance>
</PropertyGroup>
Default obfuscar.xmlfile
The default obfuscar.xml file is created using the template:
<?xml version='1.0'?>
<Obfuscator>
<Var name="InPath" value="$(ObfuscarTargetDirectory)" />
<Var name="OutPath" value="$(ObfuscarTargetDirectory)$(ObfuscarFolderName)" />
$(ObfuscarConfiguration)
$(ObfuscarPathReferences)
$(ObfuscarContent)
<Module file="$(ObfuscarTargetDirectory)$(ObfuscarFileName)">
$(ObfuscarContentModule)
</Module>
</Obfuscator>
The ObfuscarConfiguration property is used to add the default configuration to the obfuscar.xml file.
This is the default configuration (KeepPublicApi, HidePrivateApi, AnalyzeXaml, SkipGenerated)
<ObfuscarConfiguration>
<![CDATA[
<Var name="KeepPublicApi" value="true" />
<Var name="HidePrivateApi" value="true" />
<Var name="AnalyzeXaml" value="true" />
<Var name="SkipGenerated" value="true" />
]]>
</ObfuscarConfiguration>
The ObfuscarContent property is used to add extra configuration to the obfuscar.xml file.
This disable the obfuscation in private members
<ObfuscarContent>
<![CDATA[
<Var name="HidePrivateApi" value="false" />
]]>
</ObfuscarContent>
The ObfuscarContentModule property is used to add extra configuration in the module to the obfuscar.xml file.
This skip all types with the CompilerGeneratedAttribute attribute and methods inside.
<ObfuscarContentModule>
<![CDATA[
<SkipType name="*" decoratorAll="System.Runtime.CompilerServices.CompilerGeneratedAttribute" skipMethods="true" />
]]>
</ObfuscarContentModule>
Strong-Naming
If the assembly is strong-named, is necessary to add the KeyFile to the obfuscar.xml file using the ObfuscarContent property.
<ObfuscarContent Condition="$(SignAssembly)">
<![CDATA[
$(ObfuscarContent)
<Var name="KeyFile" value="$(AssemblyOriginatorKeyFile)" />
]]>
</ObfuscarContent>
Project Reference
This project use the same approach as the ricaun.ILRepack project.
License
This project is licensed under the MIT License.
Do you like this project? Please star this project on GitHub!
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.0
- Obfuscar (>= 2.2.50)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.