dotnet / command-line-api

Command line parsing, invocation, and rendering of terminal output.
https://github.com/dotnet/command-line-api/wiki
MIT License
3.38k stars 378 forks source link

System.CommandLine needs reflection to work? #1608

Open tomrus88 opened 2 years ago

tomrus88 commented 2 years ago

I've tried to compile my little app (~400 lines of C#, zero use of reflection) that references and makes use of latest System.CommandLine (2.0.0-beta3.22101.1 at the time of writing) with NativeAOT and reflection disabled (IlcDisableReflection=true) and app stopped working. Enabling reflection makes it work again. Then I tried to remove usage of System.CommandLine from the app, but keep reflection disabled and app works fine. This leads me to believe that something in System.CommandLine needs that reflection so bad? Why?

jonsequitur commented 2 years ago

Currently, .NET Interactive supports trimming and single file publishing but not native AOT. We do plan to get there in a future release.

The main place reflection is used is to create values to bind to command handlers. As we improve our source generator support, this will become unnecessary.

Are you seeing warnings for specific areas of System.CommandLine code?

tomrus88 commented 2 years ago

Thee only warning i'm seeing I posted here https://github.com/dotnet/command-line-api/issues/1465#issuecomment-1028262620

It only appears when reflection is enabled and app works. When reflection is disabled I get no warnings and app doesn't work anymore.