Linking allows Dotfuscator to combine multiple input assemblies into one or more output assemblies. This can help simplify deployment scenarios and reduce the number of files you need to distribute.
You can use linking together with other Dotfuscator features, such as Renaming and Removal. During the same build, Dotfuscator can protect your assemblies, remove unused code, and link the result into fewer output assemblies.
How Linking Works
When you configure linking, you map one or more input assemblies to an output assembly. Each input assembly can be linked into only one output assembly.
For example, if your application has input assemblies A, B, C, D, and E, you can link A, B, and C into output assembly F, and link D and E into output assembly G.
If other input assemblies reference assemblies that are being linked, Dotfuscator updates the assembly and type references so the protected output assemblies can work together.
Configure Linking
To configure linking in the Config Editor:
- Open your Dotfuscator config in the Config Editor.
- Go to the Linking tab.
- In the Linked Assemblies toolbar, click the Create New Linked Assembly icon.
- In the Output Assembly field, enter a name for the output assembly.
- From the Input Assemblies list, drag the assemblies you want to link into the new output assembly.
- Select the input assembly that should be the prime assembly.
- If needed, configure the name mangling policy and entry point.
- Repeat these steps for each output assembly you want to create.
To remove an assembly from the Linked Assemblies list, select it and click the delete button on the toolbar, or press Delete.
The screenshot below shows an example with multiple linked outputs. First, input assemblies Driver.exe and LibraryC.dll are linked into out.exe; next, LibraryA.dll and LibraryB.dll are linked into outlib.dll; and last, LibraryE.dll "passes through" without being linked.
Prime Assemblies
When you set up linking, you must specify one input assembly as the prime assembly.
Dotfuscator applies manifest information from the prime assembly, such as version number and public key, to the linked output assembly.
Name Mangling
When Dotfuscator links assemblies, it may encounter names that conflict with each other. For example, two input assemblies may contain private classes with the same name.
In most cases, Dotfuscator can safely mangle names to avoid conflicts. However, if two visible types have the same name, Dotfuscator cannot safely mangle either name without guidance.
The name mangling policy determines how Dotfuscator handles these cases. The default behavior is to stop the build with an error. Other options allow Dotfuscator to mangle one of the names and issue a warning, or silently mangle the names.
Entry Points
In .NET, an executable assembly must have an entry point. This is the method that the CLR calls when the assembly runs. The method is typically named Main, but it can have a different name.
When linking output assemblies, you may need to specify an entry point.
| Inputs | Output | Entry Point Rule |
|---|---|---|
| All inputs are EXEs | EXE | A user-specified entry point is required. Dotfuscator removes all input entry points and applies the selected entry point to the output assembly. |
| All inputs are DLLs | EXE | A user-specified entry point is required. |
| Mixed EXEs and DLLs | EXE | A user-specified entry point is required, unless there is only one input EXE. In that case, Dotfuscator uses the input EXE entry point. A user-specified entry point overrides the default. |
| Any input type | DLL | Dotfuscator removes all input entry points. The user-specified entry point is used only for .NET Core assemblies. |
Limitations
Linking has the following limitations:
- Linking is not supported for Managed C++ assemblies.
- Linking is not supported in Automatic Input Management mode.
- Dotfuscator does not update the assembly name in Pack URIs in XAML. Because of this, linking applications with XAML should generally be avoided.