commandlineparser / commandline

The best C# command line parser that brings standardized *nix getopt style, for .NET. Includes F# support
MIT License
4.46k stars 473 forks source link

Aot support? #897

Closed bertt closed 10 months ago

bertt commented 11 months ago

Hi, I'm trying to use this library with AOT (PublishAot = true) in .NET 8, but got the following warnings on publish (CommandLineParser 2.9.1):

 Generating native code
CommandLine.dll : warning IL2104: Assembly 'CommandLine' produced trim warnings. For more
 information see https://aka.ms/dotnet-illink/libraries
CommandLine.dll : warning IL3053: Assembly 'CommandLine' produced AOT analysis warnings.

And when running I see:

Unhandled Exception: System.InvalidOperationException: Type Options appears to be immutable, but no constructor found to accept values.

Type options:

public class Options
{
    private readonly bool verbose;

    public Options(bool verbose)
    {
        this.verbose = verbose;
    }
    [Option]
    public bool Verbose { get { return verbose; } }
}

Question: Is publishing with AOT supported?

bertt commented 10 months ago

found a workaround adding

[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Options))]
static void Main(string[] args)
kgamecarter commented 1 month ago

https://github.com/commandlineparser/commandline/pull/913 NativeAoT in This PR work fine. And smaller exe size.