C
C#8mo ago
Jelle

❔ Distributing a CLI app (with .NET 8 Native AOT)

Hi guys, I built a CLI app that I'd like to distribute to the major platforms (windows, mac, linux). I'm trying to deal with building and distributing the app now that I have a version that I'm happy with, though I'm running into some issues.. I thought that with .NET 8's improved Native AOT, it'd be perfect to write my app targeting that. The app's use is that it makes it easy to create files and directories etc. so I honestly don't think a self-contained app is suitable for this use-case because how can I ask people to install 100MB+ for such a simple app (though maybe I can)? I'm using CommandLineParser for dealing with the argument parsing, and using DotNetYaml in also a relatively critical part of the app, both are throwing Native AOT warnings and Trim warnings. The app crashes when creating the Options object from CommandLineParser.Parser.ParseArguments .. (this doesn't happen when running it locally with the debugger attached, only when running the executable that was built with Native AOT with dotnet publish) The exception I'm currently hitting reads as follows:
InvalidOperationException: Type ****.CommandLine.Verbs.Create.CreateVerbOptions appears to be immutable, but no constructor found to accept values.
at CommandLine.Infrastructure.ReflectionHelper.CreateDefaultImmutableInstance(Type, Type[]) + 0x11c
at CommandLine.Core.InstanceBuilder.<>c__1`1.<Build>b__1_0(Func`1 f) + 0xf
at CommandLine.Core.InstanceBuilder.Build[T](Maybe`1, Func`3, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1) + 0x111
at CommandLine.Core.InstanceChooser.MatchVerb(Func`3, IEnumerable`1, Tuple`2, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1) + 0x19f
at CommandLine.Core.InstanceChooser.<Choose>g__choose|1_1(InstanceChooser.<>c__DisplayClass1_0&) + 0x114
at CommandLine.Core.InstanceChooser.Choose(Func`3, IEnumerable`1, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1) + 0x22b
at CommandLine.Parser.ParseArguments(IEnumerable`1, Type[]) + 0xcf
InvalidOperationException: Type ****.CommandLine.Verbs.Create.CreateVerbOptions appears to be immutable, but no constructor found to accept values.
at CommandLine.Infrastructure.ReflectionHelper.CreateDefaultImmutableInstance(Type, Type[]) + 0x11c
at CommandLine.Core.InstanceBuilder.<>c__1`1.<Build>b__1_0(Func`1 f) + 0xf
at CommandLine.Core.InstanceBuilder.Build[T](Maybe`1, Func`3, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1) + 0x111
at CommandLine.Core.InstanceChooser.MatchVerb(Func`3, IEnumerable`1, Tuple`2, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1) + 0x19f
at CommandLine.Core.InstanceChooser.<Choose>g__choose|1_1(InstanceChooser.<>c__DisplayClass1_0&) + 0x114
at CommandLine.Core.InstanceChooser.Choose(Func`3, IEnumerable`1, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1) + 0x22b
at CommandLine.Parser.ParseArguments(IEnumerable`1, Type[]) + 0xcf
It honestly seems quite a lot like it's coming from the Trim and/or AOT warnings when building the project. There's a few questions I'd like to ask: 1. Any advice on how I can deal with the exception? 2. Is it even worth it for me to dig into this issue? There may be plenty more even if I solve the one I'm currently encountering 3. Am I overreacting regarding size? I guess I could just release a self-contained app but like I mentioned above, I feel like the size is too big to justify the use-case 4. Any tips or examples on proper open-source CLI apps built on .net? I'm honestly quite lost especially regarding distributing them but I'm also starting to think building it on dotnet wasnt a great choice
3 Replies
Yowl
Yowl8mo ago
What are the warnings?
Michal
Michal8mo ago
Putting <PropertyGroup><TrimMode>partial</TrimMode></PropertyGroup> in the csproj will likely clear the problem up, but you'll be left with a bigger app that you can't be sure really works (you need to retest all codepaths after publishing and keep doing that every time you make a change). as the warnings say, you chose nuget packages that are not compatible with trimming. there are other command line parsers that work fine with trimming. System.CommandLine should. I think Mono.Options does too. I don't know about YAML parsers. But if you want AOT, you need to pay attention to the warnings and choose your dependencies so that they don't generate the warnings
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.