0

I am trying to make a single file executable in C#. The program does not have alot of code, yet the output is around 50mb even when I am using PublishTrimmed. Is there a way I can decrease the size of this? Thanks.

Configuration: Debug | Any CPU Target Framework: net core 3.1 (windows) Target Runtime: win x-64 Deployment Mode: Single File / Self Contained

catlover1200
  • 21
  • 1
  • 3
  • 1
    https://github.com/dotnet/runtime/blob/main/docs/design/features/globalization-invariant-mode.md – canton7 Mar 10 '22 at 15:25
  • 3
    never publish programs in debug mode – phuclv Mar 10 '22 at 15:56
  • 2
    Do you need to deploy self-contained? If you use a framework-dependent deployment, your application will be significantly smaller. – PMF Mar 10 '22 at 20:49
  • I haven't seen your update in a long time, do you have time to check our answer. – Jiale Xue - MSFT Mar 15 '22 at 03:05
  • Hello, sorry for the delay in my response. My application is only targeting windows and should be 32 bit if this helps answer your question, I don't think I need it to be self contained. – catlover1200 Mar 15 '22 at 14:48
  • @catlover1200 Did you try my answer below? If you don't mind and it works, you could click '✔' to mark my reply as the accepted answer. It will also help others to solve the similar issue. – Jiale Xue - MSFT Mar 21 '22 at 09:40

1 Answers1

0

Set the configuration to Release instead of Debug.

You can disable Self Contained when the user has the appropriate .net runtime installed. This can save a lot of space.

If your exe contains resources such as videos, it may not be able to shrink.

Self Contained also has many benefits and saves a lot of trouble, you can check the official documentation for details.

Jiale Xue - MSFT
  • 3,560
  • 1
  • 6
  • 21
  • If it's already 50MB, you can be fairly confident that 'Self Contained' is disabled already! My personal experience with 'Publish Trimmed' is that the algorithm wasn't great at walking depndencies and subsequently produced an .exe that wouldn't run due to missing dll's! – Mitch Wheat Mar 11 '22 at 06:05
  • It seems that `self contained` has not been turned off in the current op's information. Just do my best to serve the op. – Jiale Xue - MSFT Mar 11 '22 at 06:17