@@ -142,13 +142,13 @@ internal static string ArchOptionValue(ParseResult parseResult) =>
142142 new ForwardedOption < bool > (
143143 new string [ ] { "--sc" , "--self-contained" } ,
144144 CommonLocalizableStrings . SelfContainedOptionDescription )
145- . ForwardAsMany ( o => new string [ ] { $ "-property:SelfContained= { o } " , "-property:_CommandLineDefinedSelfContained=true" } ) ;
145+ . SetForwardingFunction ( ForwardSelfContainedOptions ) ;
146146
147147 public static Option < bool > NoSelfContainedOption =
148148 new ForwardedOption < bool > (
149149 "--no-self-contained" ,
150150 CommonLocalizableStrings . FrameworkDependentOptionDescription )
151- . ForwardAsMany ( o => new string [ ] { "-property:SelfContained=false" , "-property:_CommandLineDefinedSelfContained=true" } ) ;
151+ . SetForwardingFunction ( ForwardSelfContainedOptions ) ;
152152
153153 public static readonly Option < string > TestPlatformOption = new Option < string > ( "--Platform" ) ;
154154
@@ -223,7 +223,7 @@ internal static string ResolveRidShorthandOptionsToRuntimeIdentifier(string os,
223223 return $ "{ os } -{ arch } ";
224224 }
225225
226- private static string GetCurrentRuntimeId ( )
226+ public static string GetCurrentRuntimeId ( )
227227 {
228228 var dotnetRootPath = Path . GetDirectoryName ( Environment . ProcessPath ) ;
229229 // When running under test the path does not always contain "dotnet" and Product.Version is empty.
@@ -245,6 +245,26 @@ private static string GetCurrentRuntimeId()
245245 private static string GetOsFromRid ( string rid ) => rid . Substring ( 0 , rid . LastIndexOf ( "-" ) ) ;
246246
247247 private static string GetArchFromRid ( string rid ) => rid . Substring ( rid . LastIndexOf ( "-" ) + 1 , rid . Length - rid . LastIndexOf ( "-" ) - 1 ) ;
248+
249+ private static IEnumerable < string > ForwardSelfContainedOptions ( bool arg , ParseResult parseResult )
250+ {
251+ IEnumerable < string > selfContainedProperties = new string [ ] { $ "-property:SelfContained={ arg } ", "-property:_CommandLineDefinedSelfContained=true" } ;
252+
253+ if ( ! UserSpecifiedRidOption ( parseResult ) )
254+ {
255+ var ridProperties = RuntimeArgFunc ( GetCurrentRuntimeId ( ) ) ;
256+ selfContainedProperties = selfContainedProperties . Concat ( ridProperties ) ;
257+ }
258+
259+ return selfContainedProperties ;
260+ }
261+
262+ private static bool UserSpecifiedRidOption ( ParseResult parseResult ) =>
263+ parseResult . HasOption ( RuntimeOption ) ||
264+ parseResult . HasOption ( LongFormRuntimeOption ) ||
265+ parseResult . HasOption ( ArchitectureOption ) ||
266+ parseResult . HasOption ( LongFormArchitectureOption ) ||
267+ parseResult . HasOption ( OperatingSystemOption ) ;
248268 }
249269
250270 public enum VerbosityOptions
0 commit comments