Assembly Merging
You can merge assemblies with the babel command line tool, the MSBuild Babel task, or Babel Desktop.
Avalonia applications cannot be merged. Avalonia compiles each assembly’s XAML into per-assembly CompiledAvaloniaXaml types and a single !AvaloniaResources blob, and resolves assets through avares://<AssemblyName>/… URIs keyed by assembly identity. Merging the XAML-bearing assemblies collides those types and resources and breaks avares:// resolution at runtime. To ship an Avalonia application as a single file, use assembly embedding instead, which preserves each assembly’s identity.
Merging From Command Line
Using the babel tool, you can merge assemblies by specifying the target assembly followed by the list of assembly files to be merged with the primary assembly as well as any other configuration options:
babel <primary assembly source> [<other assemblies>...] [options]The Babel Obfuscator provides several options to configure assembly merging.
—[no]copyattrs [regex]
This option allows users to specify whether Babel should copy assembly-level attributes into the primary assembly. It is also possible to specify an optional regular expression to match the attribute’s full name that should be merged. Users can enter multiple --copyattrs commands to specify several attribute filters. To disable copying assembly-level attributes, users can enter the --nocopyattrs command.
If assembly-level attributes are copied, users can use XML rules to filter the attributes to be copied or excluded using the CopyAttributes and NoCopyAttributes properties, which take a regular expression to match the assembly-level attribute full type name:
<Rule name="merge attributes" feature="merge" exclude="false">
<Target>Assembly</Target>
<Pattern>*</Pattern>
<Properties>
<NoCopyAttributes>.*TypeLibVersion</NoCopyAttributes>
</Properties>
</Rule>The CopyAttributes filter expression is used to selectively include assembly-level attributes in the merged assembly based on their fully qualified attribute type name. In other words, only the attributes that match the filter expression will be merged into the target assembly, while all others will be excluded.
On the other hand, the NoCopyAttributes filter expression is used to selectively exclude assembly-level attributes from the merged assembly based on their fully qualified attribute type name. This means that all attributes that match the filter expression will not be merged into the target assembly, while all others will be included.
—[no]internalize:
When enabled, it modifies the visibility of all the merged assembly types from public to internal.
Changing the type visibility can prevent merged types from being consumed outside the primary assembly, so this option should only be enabled if the merged types are intended to be used only by the primary assembly.
Merging From MSBuild Babel Task
To merge assmebies using the Babel task, you must define an additional ItemGroup element in the MSBuild project file. This ItemGroup contains all the assemblies you want to merge with the primary assembly. The Babel task will then use this ItemGroup to perform the merge during the build process.
Here is an example of how to define the ItemGroup element
<ItemGroup>
<MergeAssembly Include="path/to/assembly1.dll"/>
<MergeAssembly Include="path/to/assembly2.dll"/>
</ItemGroup>In this example, path/to/assembly1.dll and path/to/assembly2.dll are the paths to the assemblies you want to merge with the primary assembly. You can include as many assemblies as you need in the ItemGroup.
Once you have defined the ItemGroup, you can pass it to the Babel task using the MergeAssemblies parameter:
<Babel MergeAssemblies="@(MergeAssembly)" Internalize="true" />The Internalize attribute specifies whether to change the visibility of merged types from public to internal.
Merging From Babel Desktop
To merge 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 merge 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 Merge
Make sure the connection type is Merge. New connections select Merge automatically when the primary assembly references the dependency; otherwise click the connection and change its type.
Configure the merging options
Select the primary assembly to configure the merging options in the properties panel, such as Internalize and CopyAttributes in the Optimization group.
See Obfuscation Projects for more about the project canvas.