Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Techniques for Reducing Size of .NET Native Binaries #7285
I'm working on a UWP app being built with .NET native. Reducing the app size is very important. Are there any techniques, guidance or documentation available to help reduce the app size? Are there ways we can help the .NET native tree shaking algorithm be more effective?
Some of the simple techniques I can think of are pretty basic:
There are some types that are known to be very heavy and are better avoided. E.g. using
Then there are some properties you could add in your csproj that control what the compiler does:
Here's a chapter from an internal document that I wrote on reflection:
A major problem of compiling .NET ahead of time is predicting what code will be used at runtime. Reflection APIs allow users to access any part of the app. To keep the app small, the compiler would like to compile as little code as possible because native code tends to be bigger than IL. Not having a JIT to lean on at runtime, this puts the compiler in a tough spot.
To help the compiler solve this problem, .NET Native adds RD.XML files. RD.XML controls a couple aspects of compilation, but reflection is the most interesting one from size on disk perspective.
We use the