Custom Linker Configuration
Let us know how you feel about this
last updated: 2017-03
If the default set of options is not enough, you can drive the linking process with an XML file that describes what you want from the linker.
You can provide extra definitions to the linker to ensure the type, methods
and/or fields are not eliminated from your application. In your own code the
preferred way is to use the
[Preserve] custom attribute, as discussed
in the Linking on iOS and
Linking on Android
However if you need some definitions from the SDK or product assemblies then using an
XML file might be your best solution (versus adding code that will ensure the
linker won't eliminate what you need).
To do this, you define an XML file with the top-level element
Once you have this linker description file, add it to your project and: The following example shows what the XML file looks like: In the above example, the linker will read and apply the instructions on the The first section, for The second section, for
<field name="mono_corlib_version" />
<method name="get_StackTrace" />
<type fullname="Foo" preserve="fields">
<method name=".ctor" />
<method signature="System.Void .ctor(System.String)" />
<field signature="System.String _blah" />
<namespace fullname="My.Own.Namespace" />
<type fullname="My.Other*" />
mscorlib.dll (shipped with Mono for Android) and
My.Own.Assembly (user code) assemblies.
mscorlib.dll, will ensure that the
System.Environment type will preserve its field named
mono_corlib_version and its
Note the getter and/or setter method names must be used as the linker works on
IL and does not understand C# properties.
My.Own.Assembly.dll, will ensure that
Foo type will preserve all its fields (i.e. the
preserve="fields" attribute) and all its constructors (i.e. all
the methods named
.ctor in IL). The
will preserve specific signatures (not names) for one constructor (that
accepts a single string parameter) and for a specific string field
My.Own.Namespace namespace will preserve all the types it contains.
Lastly, any type whose full name (including the namespace) matches the wildcard
pattern "My.Other*" will preserve all of its fields and methods. The wildcard
* can be included multiple times within a "type fullname" pattern.
Once you have this linker description file, add it to your project and:
The following example shows what the XML file looks like:
In the above example, the linker will read and apply the instructions on the
The first section, for
The second section, for