The Babel Obfuscator NuGet package will allow you to deploy Babel on any build server based on .NET SDK.
The Babel.Obfuscator.nupkg NuGet package is a part of the Babel Obfuscator software and is made available for use after purchasing the Ultimate edition or one of the Babel Licensing editions. Please refer to the installation section in the documentation to learn how to set up your build environment to use the Babel Obfuscator NuGet package properly.
The Babel Obfuscator NuGet package provides the babel tool for your .NET projects. You can install the Babel Obfuscator NuGet package in your Microsoft Visual Studio projects using the NuGet Package Manager. Upon successful installation, you can proceed with building your solution. During the build process, Babel Obfuscator will obfuscate the designated target assembly.
Babel Obfuscator tool requires access to the license file during the compilation process. If you have set up the license file using the environment variable BABEL_LICENSE_PATH (as described in the License File section), no further action is needed. Otherwise, you need to copy the babel.licenses license file to your solution folder before building.
The Babel Obfuscator NuGet package can be easily added to a .NET project from the NuGet package manager. This package includes the babel build tool, which is used for obfuscating .NET assemblies.
When you add Babel.Obfuscator NuGet package to your project through the Visual Studio NuGet Package Manager, the following XML element will be added to your project file (.csproj or .vbproj file) as a PackageReference:
<PackageReference Include="Babel.Obfuscator" Version="10.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference>element, specifies the package name and version and includes additional metadata such as the assets to include and exclude. The
PrivateAssetselement is set to
allto prevent babel from being included as a dependency of the project, and the
IncludeAssetselement specifies which assets to include when the package is installed.
it is essential to include additional metadata to prevent the babel tool from being added as a reference to the built assembly. If you add the PackageReference manually to your project, this additional metadata must also be added; otherwise, the babel tool will be added as a reference in your assembly, leading to undesired behaviour. Thus, including the additional metadata is necessary to ensure the proper functioning of the Babel Obfuscator.
The customization of Babel Obfuscator can be performed by editing the Visual Studio project file. One aspect of customization that can be done is to disable Babel Obfuscator in Debug build by adding the BabelEnabled element to the PropertyGroup defined for the Debug configuration. This can be achieved by adding the following code:
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
By adding this code, Babel Obfuscator will not run during the build process in the Debug configuration. This can be useful in scenarios where you need to debug and view the un-obfuscated code without the added complexity of working with obfuscated code.
The PropertyGroup element serves as a container for the configuration-specific options. For example, you can specify different Babel Obfuscator options to fine-tune the obfuscation and meet your specific requirements.
The Babel Obfuscator NuGet package defines several MSBuild variables that can be used to customize the obfuscation process.
The Babel Obfuscator NuGet package provides several task names that can be used as entry points for MSBuild to execute additional tasks. These entry points allow developers to extend the obfuscation process.
The Babel Obfuscator NuGet package supports the latest .NET SDK versions, including NET7, NET6, and NET Core 3.1. When your build environment has one of these .NET SDK versions installed, the Babel NuGet package will automatically select the most appropriate version of Babel to run.
If your build machine has multiple .NET SDKs installed, you have the ability to specify which SDK Babel should utilize by setting the
BabelTaskDirproperty. This property allows you to explicitly define the directory path where the Babel Obfuscator assembly should be loaded.
For example, you can set the
By adjusting the path to match the location of the desired SDK version, such as
net6.0, you instruct Babel to use that specific SDK when executing the obfuscation task.
If none of the supported SDK versions is installed on your build machine, the Babel Obfuscator NuGet package will fall back to using the .NET Core 3.1 SDK as the default.
This approach ensures that Babel runs with the specified SDK version, granting you greater control over the build process and compatibility with your target environment.
Obfuscation rules can be configured by adding to the project an XML file named babelRules.xml.
If you have multiple XML rules files, you can add them to your project by configuring an ItemGroup that references all the rules files Babel Obfuscator should process, ex:
<BabelRules Include="renamingRules.xml" />
<BabelRules Include="codeRules.xml" />
The process of merging or embedding additional assemblies into the obfuscation target can be achieved by defining additional ItemGroup elements in the project file:
<MergeAssembly Include="$(TargetDir)\Acme.View.dll" />
<MergeAssembly Include="$(TargetDir)\Acme.ViewModel.dll" />
<EmbedAssembly Include="$(TargetDir)\Framework.Mvvm.dll" />
<EmbedAssembly Include="$(TargetDir)\Acme.Wpf.dll" />
When merging types from an external assembly, it is possible to change the visibility of merged types from public to internal, thereby enhancing the efficiency of the renaming process. To internalize the merged types, set the MergeInternalize property to true.
Some obfuscation features, such as renaming public interfaces, require Babel Obfuscator to access the XML mapping files of external obfuscated assemblies. In this case, you can define an ItemGroup that includes multiple MapInFile elements for each mapping file to be processed:
<MapInFile Include="$(TargetDir)\Acme.View.dll.map.xml" />
<MapInFile Include="$(TargetDir)\Acme.ViewModel.dll.map.xml" />
To generate an XML mapping file for the obfuscated target assembly, you can add the GenerateMapOutFile property to your project file.
Adding specific properties to the Visual Studio project file enables optimizations that Babel Obfuscator can perform during the obfuscation process. These optimizations may improve the performance and efficiency of the target assembly.
If you want to incorporate external plugins into your obfuscation process, you can add a reference to them by adding an ItemGroup with BabelPlugin child elements as follow:
<BabelPlugin Include="BabelEncrypt.dll" />
Where the PluginArguments property can be added to pass key-value pairs options to the referenced plugins.
The Babel Obfuscator NuGet package contains several MSBuild instructions that configure the Babel task according to the specific target assembly framework and build configuration. These instructions are designed to provide a default configuration that works for most scenarios. However, there may be cases where you need to override this configuration to suit your specific needs.
By creating a Task element named "BeforeObfuscate" in your project file, you can intervene in the build process before the Babel task is executed and modify its configuration. This allows you to customize the obfuscation settings, properties, or ItemGroup elements associated with the Babel task.
Here's an example of how you can define the "BeforeObfuscate" task and add custom properties or ItemGroup elements:
<!-- Add custom properties -->
<!-- Replace Babel search directories -->
<BabelSearchDirectories Remove="@(BabelSearchDirectories)" />
<BabelSearchDirectories Include="$(TargetDir)" />
Inside the BeforeObfuscate target, you can add custom properties and ItemGroup elements as per your requirements. These properties and ItemGroup elements can override or supplement the configuration prepared by the Babel Obfuscator NuGet package.
By adding custom properties and ItemGroup elements within the "BeforeObfuscate" target, you can customize the Babel task configuration to suit your specific needs. These customizations will be applied before the actual obfuscation process takes place.
You can add several properties related to the Babel Obfuscator NuGet package to your Visual Studio project file. These properties enable further customization of the obfuscation process, allowing you to tailor the output per your requirements. Further details about all the available properties can be found in the following section (NuGet Package Reference).
Last modified 1mo ago