-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.CommandLine defaults have large dependency closure #1794
Comments
Context: dotnet/runtime#72082 (comment) |
We have made some progress recently, but we are definitely not done yet: System.Private.Uri.dll
System.Net.Primitives.dll
- System.ObjectModel.dll
- System.ComponentModel.dll
- System.ComponentModel.Primitives.dll
- System.ComponentModel.TypeConverter.dll
- System.Collections.NonGeneric.dll
System.Runtime.Serialization.Formatters.dll
- System.Diagnostics.Process.dll |
My guess is that all of the redundant references come from here: command-line-api/src/System.CommandLine/Binding/ArgumentConverter.StringConverters.cs Line 14 in c63e231
which is just a dictionary of parsers that in theory can be used by the app: command-line-api/src/System.CommandLine/Binding/ArgumentConverter.StringConverters.cs Lines 172 to 182 in c63e231
Since internal bool TryParse(string token, out T value)
{
if (typeof(T) == typeof(IPAddress))
{
if (IPAddress.TryParse(token, out var ip))
{
value = (T)(object)ip;
return true;
}
value = default;
return false;
}
// else if (typeof(T)...
} @jkotas Does trimmer recognize such typeof checks? If not, how can I get rid of these references? |
@adamsitnik, very nice! Should/can we update https://github.com/dotnet/runtime/blob/f561a058b13523c4b045803c9876e823b4cfe0fc/eng/Versions.props#L174 to latest revision? It's four months old and seems like we don't have a darc subscription in runtime repo for command-line-api (dotnet/format, dotnet/sdk etc. have such a subscription). |
Trimmer does not recognize patterns like these.
This is yet another deserializer. You can look at e.g. how we have solved this problem for System.Text.Json deserializer. The general shape of the solution is:
|
We should, but I should not do it myself, as I introduced all the breaking changes and they are reasonable and easy to fix for me. I am about to write a doc that lists all the breaking changes, explains the reasoning behind them and how to solve the issues. @am11 would you be interested in updating dotnet/runtime once I have the doc ready? And share some feedback about whether the changes are move in the right direction or not? |
With #2127 the only dependency is And updated perf numbers for startup scenario with default settings (all features enables, https://github.com/adamsitnik/commandline-perf/tree/update):
|
This doesn't seem to have been done, so anyone using Argument<Uri> will have to set a custom parser function and custom localization of error messages. |
That is true. But in the long term (.NET 9) we are going to provide a source-generator for System.CommandLine and all parsable types will be supported out of the box. |
Repro
dotnet publish -c Release -r win-x64 /p:PublishTrimmed=true
Actual result:
The trimmed application has referenced to many types and binaries that should not be needed:
Expected result:
The trimmed application should only reference types and binaries that are actually needed.
The text was updated successfully, but these errors were encountered: