@@ -34,6 +34,7 @@ internal abstract class InstallingWorkloadCommand : WorkloadCommandBase
3434 protected readonly SdkFeatureBand _sdkFeatureBand ;
3535 protected readonly ReleaseVersion _targetSdkVersion ;
3636 protected readonly string _fromRollbackDefinition ;
37+ protected string _workloadSetVersion ;
3738 protected readonly PackageSourceLocation _packageSourceLocation ;
3839 protected readonly IWorkloadResolverFactory _workloadResolverFactory ;
3940 protected IWorkloadResolver _workloadResolver ;
@@ -96,6 +97,53 @@ protected static Dictionary<string, string> GetInstallStateContents(IEnumerable<
9697 manifestVersionUpdates . Select ( update => new WorkloadManifestInfo ( update . ManifestId . ToString ( ) , update . NewVersion . ToString ( ) , /* We don't actually use the directory here */ string . Empty , update . NewFeatureBand ) )
9798 ) . ToDictionaryForJson ( ) ;
9899
100+ public static bool ShouldUseWorkloadSetMode ( SdkFeatureBand sdkFeatureBand , string dotnetDir )
101+ {
102+ string path = Path . Combine ( WorkloadInstallType . GetInstallStateFolder ( sdkFeatureBand , dotnetDir ) , "default.json" ) ;
103+ var installStateContents = File . Exists ( path ) ? InstallStateContents . FromString ( File . ReadAllText ( path ) ) : new InstallStateContents ( ) ;
104+ return installStateContents . UseWorkloadSets ?? false ;
105+ }
106+
107+ protected IEnumerable < ManifestVersionUpdate > HandleWorkloadUpdateFromVersion ( ITransactionContext context , DirectoryPath ? offlineCache )
108+ {
109+ // Ensure workload set mode is set to 'workloadset'
110+ // Do not skip checking the mode first, as setting it triggers
111+ // an admin authorization popup for MSI-based installs.
112+ if ( ! ShouldUseWorkloadSetMode ( _sdkFeatureBand , _dotnetPath ) )
113+ {
114+ _workloadInstaller . UpdateInstallMode ( _sdkFeatureBand , true ) ;
115+ }
116+
117+ _workloadManifestUpdater . DownloadWorkloadSet ( _workloadSetVersion , offlineCache ) ;
118+ return InstallWorkloadSet ( context ) ;
119+ }
120+
121+ public IEnumerable < ManifestVersionUpdate > InstallWorkloadSet ( ITransactionContext context )
122+ {
123+ var advertisingPackagePath = Path . Combine ( _userProfileDir , "sdk-advertising" , _sdkFeatureBand . ToString ( ) , "microsoft.net.workloads" ) ;
124+ if ( File . Exists ( Path . Combine ( advertisingPackagePath , Constants . workloadSetVersionFileName ) ) )
125+ {
126+ // This file isn't created in tests.
127+ PrintWorkloadSetTransition ( File . ReadAllText ( Path . Combine ( advertisingPackagePath , Constants . workloadSetVersionFileName ) ) ) ;
128+ }
129+ var workloadSetPath = _workloadInstaller . InstallWorkloadSet ( context , advertisingPackagePath ) ;
130+ var files = Directory . EnumerateFiles ( workloadSetPath , "*.workloadset.json" ) ;
131+ return _workloadManifestUpdater . ParseRollbackDefinitionFiles ( files ) ;
132+ }
133+
134+ private void PrintWorkloadSetTransition ( string newVersion )
135+ {
136+ var currentVersion = _workloadResolver . GetWorkloadVersion ( ) ;
137+ if ( currentVersion == null )
138+ {
139+ Reporter . WriteLine ( string . Format ( Strings . NewWorkloadSet , newVersion ) ) ;
140+ }
141+ else
142+ {
143+ Reporter . WriteLine ( string . Format ( Strings . WorkloadSetUpgrade , currentVersion , newVersion ) ) ;
144+ }
145+ }
146+
99147 protected async Task < List < WorkloadDownload > > GetDownloads ( IEnumerable < WorkloadId > workloadIds , bool skipManifestUpdate , bool includePreview , string downloadFolder = null ,
100148 IReporter reporter = null , INuGetPackageDownloader packageDownloader = null )
101149 {
@@ -204,6 +252,11 @@ internal static class InstallingWorkloadCommandParser
204252 Hidden = true
205253 } ;
206254
255+ public static readonly CliOption < string > WorkloadSetVersionOption = new ( "--version" )
256+ {
257+ Description = Strings . WorkloadSetVersionOptionDescription
258+ } ;
259+
207260 public static readonly CliOption < bool > PrintDownloadLinkOnlyOption = new ( "--print-download-link-only" )
208261 {
209262 Description = Strings . PrintDownloadLinkOnlyDescription ,
0 commit comments