fsprojects / Argu

A declarative CLI argument parser for F#
https://fsprojects.github.io/Argu
MIT License
453 stars 75 forks source link

[Query] Is .net7 support for trimmed binaries planned? #181

Closed jmhickman closed 1 year ago

jmhickman commented 1 year ago

Description

I have a small app that uses Argu. When I built it against .net 7 with trimming enabled, the argument configuration seems to break, showing only a generic --help item.

dotnet publish -p:PublishSingleFile=true -p:PublishTrimmed=true -r:win-x64 --self-contained -c release

This works fine in .net 6, but I'm supposing that changes to the trimming mechanism in .net 7 has made it more aggressive.

In order to figure out if I can continue to use Argu, I need to know if this is a breaking change that's just inherent to how Argu works, or if trimming can be supported with some (hopefully) minor tweak.

Not treating this as a bug, since there was no assertion that Argu worked with .net 7 and trimming, etc.

Thanks.

pkese commented 1 year ago

In my experience, even specifying just --self-contained (without -p:PublishSingleFile=true -p:PublishTrimmed=true) is enough for executable to stop working.

https://learn.microsoft.com/en-us/dotnet/core/compatibility/deployment/7.0/trim-all-assemblies

eiriktsarpalis commented 1 year ago

No plans at all. The library uses reflection by design as such it is unsuitable for trimmed applications. Consider using a newer library such as System.CommandLine instead.

pkese commented 1 year ago

@eiriktsarpalis
Maybe just adding some attributes on some specific places would suffice to inform the trimmer that it should keep certain types around for runtime reflection.

https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming#dynamicallyaccessedmembers

Another valuable thing would be to explore the problem and give guidelines in the README file or on the documentation page of how to circumvent the problem when deploying their app to production.

E.g. telling people that adding <TrimMode>partial</TrimMode> to their .fsproj file would apparently make their --self-contained apps on .net 7.0 work just like they did on .net 6.0.