Kyome22 / RunCat_for_windows

A cute running cat animation on your windows taskbar.
Apache License 2.0
6.47k stars 587 forks source link

feat: trim executable #98

Closed greenhandatsjtu closed 2 years ago

greenhandatsjtu commented 2 years ago

Now the executable is too large (over 100MB), I trim the executable size by setting PublishTrimmed in RunCat.csproj PublishWithDotNetProdile.pubxml. ref: https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained

size before is 147,800KB: image

size after is 84,974KB: image

somnisomni commented 2 years ago

Did you able to turn on trimming without any warning messages? I got a warning message when I turn the option on,

NETSDK1175: Windows Forms is not supported or recommended with trimming enabled. Please go to https://aka.ms/dotnet-illink/windows-forms for more details.

... because the program uses WinForms components.

greenhandatsjtu commented 2 years ago

Hi @somnisomni , yes, I didn't get any warnings, I run this command to publish:

dotnet publish -c Release -o publish -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true -p:IncludeNativeLibrariesForSelfExtract=true

image The output is in Chinese, in English it reads:

Microsoft (R) Generation Engine for .NET version 16.11.2+f32259642
Copyright (C) Microsoft Corporation. all rights reserved.

  Determining which items to restore...
  All projects are up to date and cannot be restored.
  RunCat -> C:\Users\sunhengke\Downloads\RunCat_for_windows\RunCat\bin\Release\net5.0-windows\win-x64\RunCat.dll
  The size of the assembly is being optimized, which may change the behavior of the application. Please be sure to test it after the release. See: https://aka.ms/dotnet-illink
  RunCat -> C:\Users\sunhengke\Downloads\RunCat_for_windows\publish\

I'm not sure if this patch is harmful, but it does significantly reduce the size of the executable, and I can run the executable as before. If you think it's not a good idea, I'll close this PR though.


BTW, the version of dotnet I'm using is 5.0.408

somnisomni commented 2 years ago

Hmm... that's interesting... I'm using .NET 6 SDK, maybe the warning message is dependent on SDK version..? I'm not sure...

greenhandatsjtu commented 2 years ago

Hmm... that's interesting... I'm using .NET 6 SDK, maybe the warning message is dependent on SDK version..? I'm not sure...

Maybe you can try .NET 5, it seems that the project only supports .NET 5 for now: https://github.com/Kyome22/RunCat_for_windows/issues/86

somnisomni commented 2 years ago

For now I'm working on my forked repository and switched to .NET 6, if trimming is working without any problem on this original repo (based on .NET 5) that should be fine. but if @Kyome22 decide to make some transition to .NET 6 in future, this could be a problem in that time.

Anyway this should be fine for now ;)

Kyome22 commented 2 years ago

@somnisomni Thanks for addressing the issue. I am not familiar with .NET, but should I give it to .NET 6?

somnisomni commented 2 years ago

.NET 5 is deprecated (ref), and .NET 6 will be supported in LTS term. so I would recommend to upgrade .NET version if you decided to.

but from a different point of view, like #84, the program does not use any modern feature. Lowering .NET version is not a really bad idea in perspective on compatibility.

Kyome22 commented 2 years ago

@greenhandatsjtu Please reconsider as I have changed to use .NET 6.

greenhandatsjtu commented 2 years ago

@greenhandatsjtu Please reconsider as I have changed to use .NET 6.

Yeah, as we discussed above, trimming executable under .NET 6 will get some warnings. As you have decided to upgrade to .NET 6, I'll close this PR. Thank you :)