2

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
Stefan
  • 17,448
  • 11
  • 60
  • 79

1 Answers1

3

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.

Stefan
  • 17,448
  • 11
  • 60
  • 79
  • 1
    Release config didn't affect the size of the .exe. It is still 140MB. But "self-contained" disabling reduced it to 7MB. Thank you! –  Feb 13 '22 at 07:06
  • You're welcome. Happy coding :) – Stefan Feb 13 '22 at 07:10
  • 3
    @Sreawqy: I added the big benifit of using self-contained. Its worth to consider that as well. – Stefan Feb 13 '22 at 07:16