add .NET 6 target framework for System.CommandLine and add support for trimming#1572
Conversation
| else | ||
| if (type == typeof(string)) | ||
| { | ||
| enumerableInterface = type |
There was a problem hiding this comment.
Typically this kind of pattern is trimming safe, but the trimmer doesn't know that you are only looking for one interface. Since you are hard-coding looking for typeof(IEnumerable), the trimmer will never trim the IEnumerable interface. It could trim other interfaces (which is why GetInterfaces is marked as unsafe). But you don't care about the other interfaces, so you can suppress this.
See the following for the same examples, and reasoning:
5c70edc to
35bc538
Compare
35bc538 to
7065aab
Compare
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <TrimmableAssembly Include="System.CommandLine" /> |
There was a problem hiding this comment.
I don't think this is needed since you set IsTrimmable=true in the assembly.
There was a problem hiding this comment.
Don't you want TrimmerRootAssembly instead?
https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <SystemCommandLineDllPath Condition="'$(SystemCommandLineDllPath)'==''">..\..\System.CommandLine\bin\Release\netstandard2.0\System.CommandLine.dll</SystemCommandLineDllPath> |
There was a problem hiding this comment.
Why not just a ProjectReference?
Also - don't point to ns2.0 build. Point to net6.0.
There was a problem hiding this comment.
Since you aren't using a ProjectReference, all the warnings from System.CommandLine are getting collapsed into a single warning IL2014.
Here's the logic that says to not collapse warnings for ProjectReferences:
If you can't use a ProjectReference here, you can still get full warnings for this assembly by setting the TrimmerSingleWarn=false metadata on the System.CommandLine assembly.
Alternatively, since your app only uses System.CommandLine, it would be simpler to just turn off the single warning behavior globally:
<PropertyGroup>
<TrimmerSingleWarn>false</TrimmerSingleWarn>fyi @sbomer
| @@ -0,0 +1,97 @@ | |||
| // adapted from: https://github.com/dotnet/runtime/blob/a5159b1a8840632ad34cf59c5aaf77040cb6ceda/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/UnconditionalSuppressMessageAttribute.cs#L21 | |||
|
|
|||
| #if !NET6_0_OR_GREATER | |||
There was a problem hiding this comment.
(nit) you use NET5_0_OR_GREATER elsewhere, but 6 here.
This is so far just a sketch of an approach to support trimming of apps using System.CommandLine. There are a large number of types that won't be bindable without a custom binder or source generator. This also removes support for using
TypeConverterAttributeand default type converters.This will fix #1465.