Make Windows Forms exe smaller?
Hello!
I wrote a Windows Forms app in .NET 7. The EXE that is created upon publishing should be standalone (including the framework) and as small as possible. I currently have about 1200 LoC, which brings me to just under 150MB.
For .net7 console applications, I was used to setting PublishTrimmed to true, and I also always used these settings:
<TrimmerRootAssembly Include="assemblyName" TrimMode="copy" />
and
<link>
<assembly fullname="assemblyName" preserve="all"/>
</link>
These settings brought me to under 15 mb for a console application (incl. runtime)
Unfortunately, when publishing with the Windows Forms app (with PublishTrimmed set to true), I got the message: "Windows Forms is not supported or recommended with cropping enabled."
I hope for your help to make the exe smaller.. 150mb is pretty extreme for such a small application with no dependencies.
Maybe you have some tips, unfortunately I haven't found anything online that helps^^
Best regards,
Oli
Trimming is problematic in applications that work with Reflection or COM-Marshalling, because during the analysis process it is difficult to assess what can be done or not. Windows Forms is particularly affected at the point, as it builds on COM-Marshalling under the hood. A possible solution in place is the use of COM wrappers (see e.g. WinFormsComInterop).
In addition, you should use the Microsoft article Prepare libraries for trimming work.
A guarantee that you can do it, but there is not. Pages of the .NET team here) there is no official support yet. This Epic provides an overview of the current development status: #4649 Make WinForms trim compatible.
Another few other options you could try/start:
wow super thanks! I needed this overview, so I can continue working:) very nice, sweetheart
@
I also praise you.
How can you be so smart? Respect. I want to go. You are now my model now. Officially, I’m also a fan of you.
then write you nen assembler code;) 150mb is not