Skip to Content
New release 12 available 🎉
ObfuscatorMerge and EmbedAssembly Embedding

Assembly Embedding

Babel Obfuscator provides a feature to embed multiple assemblies into the main application, which can reduce the overall size of the deployed assembly. When embedding assemblies with Babel Obfuscator, the embedded assemblies are first encrypted and compressed before being stored as managed resources within the main application assembly.

It is important to note that embedded assemblies are not obfuscated. Therefore, it’s recommended only to embed assemblies that do not contain proprietary code or components that are not meant to be protected.

Embedding is the recommended way to produce a single-file Avalonia application. Because embedded assemblies keep their original identity, Avalonia’s avares://<AssemblyName>/… resource URIs still resolve — unlike merging, which is not compatible with Avalonia.

To protect the code as well, obfuscate each dependency first (keeping its public API so cross-assembly references stay intact), then embed the already-obfuscated assemblies:

babel MyApp.View.dll --output obf/MyApp.View.dll [obfuscation options] babel MyApp.dll --embed obf/MyApp.View.dll [obfuscation options]

Embedding From Command Line

To embed assemblies from the command line using the Babel tool, you can use the --embed option followed by the assembly file path to embed. You can enter the command multiple times to embed several assemblies.

babel MyApp.exe --embed Library1.dll --embed Library2.dll

This command will embed Library1.dll and Library2.dll into MyApp.exe. The embedded assemblies will be stored as managed resources within the main assembly.

You can also use an XML rules file to specify additional settings, such as compression or encryption. For example, create a file named embed.xml with the following contents:

<Rules> <Rule name="Library1" feature="embed" exclude="false"> <Target>Assembly</Target> <Pattern>Library1.dll</Pattern> <Properties> <Compress>false</Compress> </Properties> </Rule> <Rule name="Library2" feature="embed" exclude="false"> <Target>Assembly</Target> <Pattern>Library2.dll</Pattern> <Properties> <Encrypt>false</Encrypt> </Properties> </Rule> </Rules>

Then run the following command to embed the assemblies based on the rules file:

babel MyApp.exe --embed Library1.dll --embed Library2.dll --rules embed.xml

Embedding From MSBuild Babel Task

To embed assemblies using the MSBuild Babel task, you need to add a new ItemGroup element in your project file. Inside the ItemGroup, you can define multiple EmbedAssembly items, each one specifying a path to an assembly file to embed. For example:

<ItemGroup> <EmbedAssembly Include="path/to/Assembly1.dll" /> <EmbedAssembly Include="path/to/Assembly2.dll" /> </ItemGroup>

You can reference the EmbedAssembly in the Babel task using the EmbedAssemblies attribute:

<Babel EmbedAssemblies="@(EmbedAssembly)" RulesFiles="embed.xml" />

You can optionally specify a rule file to customize the compression and encryption settings for each embedded assembly. By default, embedded assemblies are compressed and encrypted using Babel’s default settings, but a rule file can be used to customize these settings if necessary.

Embedding From Babel Desktop

To embed assemblies using Babel Desktop, follow these steps:

Open or create a project

Open an existing project or create a new one.

Add the assemblies

Add the primary assembly and the assemblies to embed to the project canvas.

Connect the dependencies

Connect each dependency to the primary assembly: drag from the bottom anchor of the dependency to the top anchor of the primary assembly.

Set the connection type to Embed

Click the connection and set its type to Embed. New connections default to Merge when the primary assembly references the dependency, otherwise to Reference.

Configure compression and encryption

Configure the compression and encryption of the embedded assemblies with XML rules in the XML rules view of the primary assembly.

See Obfuscation Projects for more about the project canvas.

Last updated on