Shrinking the app package
No app uses all the features of all the included libraries. The .NET libraries are quite big, and we often only use a tiny subset. To reduce the size of an app, we need to remove any unnecessary code or libraries that exist in it.
How to do it...
To reduce the overall size of the app, we enable the linker. This is used to remove any unused code from our app, or from any assemblies that are used:
- We select either the Link SDK assemblies only option or the Link all assemblies option from the Linker behavior dropdown:
- When we link assemblies, types and members are removed. To prevent members from being removed, we can add the
[Preserve]
attribute to those members:public class MyClass { [Preserve] public string MyMember() { } }
- We can also request that the linker skip all the members on an entire type:
[Preserve(AllMembers = true)] public class MyClass { }
- If we can't, or don't, want to use the
[Preserve]
attribute, we can provide a block...