I have a very small project (WinForms, it contains 2 folders and 10 classes, simple windows for input) and I want to publish it to folder as single .exe file. When it is done the size of the file is 140MB. When I add "Trim unused assemblies" mark - 90 MB.
How can I add reduce the size this .exe file? I faced something like this before, and the size of the file was about 1 MB.
My publish config:
Configuration: Debug | Any CPU
Target framework: net5.0 windows
Deployment mode: self-contained (produce single file)
Target runtime: win x-86
Thank you in advance!
CodePudding user response:
Set the configuration to Release
instead of Debug
.
That will already add some optimazation.
The self-contained
part should be disabled when optimizing for size. Disabling it will leave out the .net runtime, otherwise being embedded partially which saves space, but you must be sure the user has the appropriate .net runtime installed.
If your folders contain big files which are embedded, resources like videos, then there's nothing that can be done.
If it's a small project you can consider "just to compile it". If you're not using any non standard DLLs it result in a single (smaller) exe.
I am actually pretty fond of the self-contained
option: it saves me the hassle of making sure the user/system has the correct .net vesion installed.