diff --git a/src/Cli/dotnet/commands/dotnet-workload/search/WorkloadSearchVersionsCommand.cs b/src/Cli/dotnet/commands/dotnet-workload/search/WorkloadSearchVersionsCommand.cs index d9e3667c963b..64e14d4fc4d1 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/search/WorkloadSearchVersionsCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-workload/search/WorkloadSearchVersionsCommand.cs @@ -26,6 +26,7 @@ internal class WorkloadSearchVersionsCommand : WorkloadCommandBase private readonly string _workloadSetOutputFormat; private readonly FileBasedInstaller _installer; private readonly string _workloadVersion; + private readonly bool _includePreviews; public WorkloadSearchVersionsCommand( ParseResult result, @@ -64,6 +65,10 @@ public WorkloadSearchVersionsCommand( ); _workloadVersion = result.GetValue(WorkloadSearchVersionsCommandParser.WorkloadVersionArgument); + + _includePreviews = result.HasOption(WorkloadSearchVersionsCommandParser.IncludePreviewsOption) ? + result.GetValue(WorkloadSearchVersionsCommandParser.IncludePreviewsOption) : + new SdkFeatureBand(_sdkVersion).IsPrerelease; } public override int Execute() @@ -76,7 +81,7 @@ public override int Execute() List versions; try { - versions = PackageDownloader.GetLatestPackageVersions(packageId, _numberOfWorkloadSetsToTake, packageSourceLocation: null, includePreview: !string.IsNullOrWhiteSpace(_sdkVersion.Prerelease)) + versions = PackageDownloader.GetLatestPackageVersions(packageId, _numberOfWorkloadSetsToTake, packageSourceLocation: null, includePreview: _includePreviews) .GetAwaiter().GetResult() .Select(version => WorkloadSetVersion.FromWorkloadSetPackageVersion(featureBand, version.ToString())) .ToList(); diff --git a/src/Cli/dotnet/commands/dotnet-workload/search/WorkloadSearchVersionsCommandParser.cs b/src/Cli/dotnet/commands/dotnet-workload/search/WorkloadSearchVersionsCommandParser.cs index d40d53193457..3b06459ca715 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/search/WorkloadSearchVersionsCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-workload/search/WorkloadSearchVersionsCommandParser.cs @@ -23,6 +23,8 @@ internal static class WorkloadSearchVersionsCommandParser Description = LocalizableStrings.FormatOptionDescription }; + public static readonly CliOption IncludePreviewsOption = new("--include-previews"); + private static readonly CliCommand Command = ConstructCommand(); public static CliCommand GetCommand() @@ -36,6 +38,7 @@ private static CliCommand ConstructCommand() command.Arguments.Add(WorkloadVersionArgument); command.Options.Add(FormatOption); command.Options.Add(TakeOption); + command.Options.Add(IncludePreviewsOption); TakeOption.Validators.Add(optionResult => { diff --git a/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkFeatureBand.cs b/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkFeatureBand.cs index 336f5d0f1a42..eec3e34e68c1 100644 --- a/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkFeatureBand.cs +++ b/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkFeatureBand.cs @@ -29,6 +29,7 @@ public SdkFeatureBand(ReleaseVersion version) } } + public bool IsPrerelease => !string.IsNullOrEmpty(_featureBand.Prerelease); public int Major => _featureBand.Major; public int Minor => _featureBand.Minor;