Zack.DotNetTrimmer, a .NET Core tailor, has updated the engine and supported recording and playback
Last week, I published an open source program for slimming .NET Core applications, which is Zack.DotNetTrimmer. Compared with. NET Core built-in trimmer, Zack.DotNetTrimmer not only can compresses more, but also supports WPF and WinForm. Here is the comparison between Zack.DotNetTrimmer and .NET built-in trimmer:
Within a week, the related articles have been read more than 40,000 times, and the project has gained nearly 200 stars. Users left a lot of feedback, so I upgraded it this week. This article will introduce the new features.
New Feature 1. Supports of recording and playback of trimming plans
By default, this program will trim the program as soon as the clipped program exits. On more complex projects, however, you may need to run the program multiple times in different environments to cover the entire path of the code before trimming it.
The program supports two modes: Record and Apply. In Record mode, the program will record the running information of the program to a JSON file. If the JSON file already exists, the program will append the information to the JSON file.
After we run the program to be trimmed in Record mode for many times, we run the program with the Apply model again and specify the JSON file recorded previously. The program will trim the program according to the recorded JSON file.
For example, we start the program to be clipped in record mode, specify to record the trimming plan in d:/1.json file, and then test the program as user A. We then start the program to be clipped in record mode, again specify to record the trimming plan to the D:/1.json file, and test the program as user B to cover the code that was not covered when running as user A. Finally, we start the program to be trimmed in “Apply Mode”, specify the trimming plan file as D:/1.json, so that Zack.DotNetTrimmer will combine the two code loads of “Record mode” and then trimming the program.
This feature can be used for automated testing, as long as you ensure that the trimming plans for multiple automated test programs use the same record file.
This feature also can be used for automatic build. We can reuse the trimming plan file completed in advance, so as to run Zack.DotNetTrimmer in apply mode after the program is published, so as to realize automatic trimming of the program.
New Feature2. Removing unused classes
By default, Zack.DotNetTrimmer removes assemblies that have not been loaded. We know that there may still be classes in the loaded assembly that are not being used, and if we can trim those classes, we can compress the application further.
The new version of Zack.DotNetTrimmer supports the “greedy” option, which, when enabled, attempts to remove unused classes from an assembly. Taking the WinForm version of TeeChart as an example, using the default option, the program was compressed from 161.78 MB to 79.90 MB, and using the greedy option, the program was further compressed to 78.38 MB, which removed 1.52 MB of useless code.
Limited by technical implementation, it is currently unable to clean up classes in assemblies that contain native code (such as NGen), and it only removes the method body of the class, not the class entirely. I will continue to work on it and welcome your feedback and suggestions.
Repository : https://github.com/yangzhongke/Zack.DotNetTrimmer
I will write a post to explain how it works, please leave a like and subscribe.