A better .NET Core trimmer, reduce the program size to 30%

Zack Yang
2 min readMar 8, 2022

Why I developed an application trimmer for .NET Core?

.NET Core has the capability of tailoring unused code, however, because it is implemented using static analysis, its tailoring is not optimal. It has the following two disadvantages:

  1. It doesn’t support Windows Forms or WPF, and it’s desktop developers who are most eager to tailor applications.
  2. It cannot delete assemblies that are not being used at runtime. For example, our program uses assembly A, which in turn references two assemblies B and C. Only method M1 in assembly A uses assembly B, and only method M2 in assembly A uses assembly C. Our program only calls M1 in A, but never M2 in A. Although the C assembly has not been called, the ‘tailoring unused code’ function does static reference checking, so the C assembly will not be removed.
  3. It doesn’t support reflection very well. Because it is implemented using static analysis, it may remove assemblies that would only be loaded by reflection at runtime.

In contrast, Zack.DotNetTrimmer supports Windows Forms and WPF. It analyzes the assemblies loaded by an application at runtime to check which assemblies are not being used, so it not only deletes more assemblies that are not being used, but also naturally ** supports reflection ** . Every advantage has its disadvantage, the downside of Zack.dotnetTrimmer is that it requires you to run the project to be trimmed and run through all the functionality in the program so that you can detect assemblies that will not be used under any circumstances.

Comparison of trimming

Comparison of trimming

How to download and use it?
To obtain the project open source address and detailed usage please visit https://github.com/yangzhongke/Zack.DotNetTrimmer/

How it works?

The Diagnostics library provided by Microsoft can get all the runtime information of .NET applications. My program uses the type DiagnosticsClient to check the loaded assemblies at runtime, so that you know which assemblies are not being used.

--

--