Skip to content

Commit 904eb64

Browse files
committed
Fix issue garbage collecting cross-feature band workload set, add errors for combinations with skip manifest update
1 parent 708f383 commit 904eb64

18 files changed

+184
-27
lines changed

src/Cli/dotnet/commands/InstallingWorkloadCommand.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ internal abstract class InstallingWorkloadCommand : WorkloadCommandBase
3636
protected readonly ReleaseVersion _targetSdkVersion;
3737
protected readonly string _fromRollbackDefinition;
3838
protected string _workloadSetVersionFromCommandLine;
39+
protected string _globalJsonPath;
3940
protected string _workloadSetVersionFromGlobalJson;
4041
protected readonly PackageSourceLocation _packageSourceLocation;
4142
protected readonly IWorkloadResolverFactory _workloadResolverFactory;
@@ -99,12 +100,12 @@ public InstallingWorkloadCommand(
99100
_workloadInstallerFromConstructor = workloadInstaller;
100101
_workloadManifestUpdaterFromConstructor = workloadManifestUpdater;
101102

102-
var globaljsonPath = SdkDirectoryWorkloadManifestProvider.GetGlobalJsonPath(Environment.CurrentDirectory);
103-
_workloadSetVersionFromGlobalJson = SdkDirectoryWorkloadManifestProvider.GlobalJsonReader.GetWorkloadVersionFromGlobalJson(globaljsonPath);
103+
_globalJsonPath = SdkDirectoryWorkloadManifestProvider.GetGlobalJsonPath(Environment.CurrentDirectory);
104+
_workloadSetVersionFromGlobalJson = SdkDirectoryWorkloadManifestProvider.GlobalJsonReader.GetWorkloadVersionFromGlobalJson(_globalJsonPath);
104105

105106
if (SpecifiedWorkloadSetVersionInGlobalJson && (SpecifiedWorkloadSetVersionOnCommandLine || UseRollback))
106107
{
107-
throw new GracefulException(string.Format(Strings.CannotSpecifyVersionOnCommandLineAndInGlobalJson, globaljsonPath), isUserError: true);
108+
throw new GracefulException(string.Format(Strings.CannotSpecifyVersionOnCommandLineAndInGlobalJson, _globalJsonPath), isUserError: true);
108109
}
109110

110111
if (SpecifiedWorkloadSetVersionOnCommandLine && UseRollback)

src/Cli/dotnet/commands/dotnet-workload/install/LocalizableStrings.resx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@
322322
<data name="CannotCombineSkipManifestAndRollback" xml:space="preserve">
323323
<value>Cannot use the {0} and {1} options together. If installing from a rollback file, remove {0}. Otherwise, remove {1}</value>
324324
</data>
325+
<data name="CannotCombineSkipManifestAndVersion" xml:space="preserve">
326+
<value>Cannot use the {0} and {1} options together. Remove one of the options.</value>
327+
</data>
328+
<data name="CannotUseSkipManifestWithGlobalJsonWorkloadVersion" xml:space="preserve">
329+
<value>Cannot use the {0} option when workload version is specified in global.json. Remove the {0} option, or remove the 'workloadVersion' element from {1}.</value>
330+
<comment>"workloadVersion" is a literal value and should not be translated.</comment>
331+
</data>
325332
<data name="SkipSignCheckOptionDescription" xml:space="preserve">
326333
<value>Skip signature verification of workload packages and installers.</value>
327334
</data>

src/Cli/dotnet/commands/dotnet-workload/install/WorkloadGarbageCollector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void GarbageCollectWorkloadSets()
7777
foreach (var set in installedWorkloadSets.Keys)
7878
{
7979
WorkloadSetsToKeep.Add(set);
80+
_verboseReporter.WriteLine($"GC: Keeping workload set version {set} because workload set GC isn't implemented yet.");
8081
}
8182

8283
var installStateFilePath = Path.Combine(WorkloadInstallType.GetInstallStateFolder(_sdkFeatureBand, _dotnetDir), "default.json");

src/Cli/dotnet/commands/dotnet-workload/install/WorkloadInstallCommand.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public WorkloadInstallCommand(
4343

4444
_workloadManifestUpdater = _workloadManifestUpdaterFromConstructor ?? new WorkloadManifestUpdater(Reporter, _workloadResolver, PackageDownloader, _userProfileDir,
4545
_workloadInstaller.GetWorkloadInstallationRecordRepository(), _workloadInstaller, _packageSourceLocation, displayManifestUpdates: Verbosity.IsDetailedOrDiagnostic());
46-
47-
4846
}
4947

5048
private void ValidateWorkloadIdsInput()
@@ -108,32 +106,28 @@ public override int Execute()
108106
WorkloadInstallCommandParser.SkipManifestUpdateOption.Name, InstallingWorkloadCommandParser.FromRollbackFileOption.Name,
109107
WorkloadInstallCommandParser.SkipManifestUpdateOption.Name, InstallingWorkloadCommandParser.FromRollbackFileOption.Name), isUserError: true);
110108
}
109+
else if (_skipManifestUpdate && SpecifiedWorkloadSetVersionOnCommandLine)
110+
{
111+
throw new GracefulException(string.Format(LocalizableStrings.CannotCombineSkipManifestAndVersion,
112+
WorkloadInstallCommandParser.SkipManifestUpdateOption.Name, InstallingWorkloadCommandParser.VersionOption.Name), isUserError: true);
113+
}
114+
else if (_skipManifestUpdate && SpecifiedWorkloadSetVersionInGlobalJson)
115+
{
116+
throw new GracefulException(string.Format(LocalizableStrings.CannotUseSkipManifestWithGlobalJsonWorkloadVersion,
117+
WorkloadInstallCommandParser.SkipManifestUpdateOption.Name, _globalJsonPath), isUserError: true);
118+
}
111119
else
112120
{
113-
bool shouldUpdateWorkloads = !_skipManifestUpdate;
114-
115121
try
116122
{
117123
// Normally we want to validate that the workload IDs specified were valid. However, if there is a global.json file with a workload
118-
// set version specified, and we might update the workload version, then we don't do that check here, because we might not have the right
124+
// set version specified, and we might install that workload version, then we don't do that check here, because we might not have the right
119125
// workload set installed yet, and trying to list the available workloads would throw an error
120-
if (!shouldUpdateWorkloads || string.IsNullOrEmpty(_workloadSetVersionFromGlobalJson))
126+
if (_skipManifestUpdate || string.IsNullOrEmpty(_workloadSetVersionFromGlobalJson))
121127
{
122128
ValidateWorkloadIdsInput();
123129
}
124130

125-
if (string.IsNullOrWhiteSpace(_workloadSetVersionFromCommandLine) && string.IsNullOrWhiteSpace(_workloadSetVersionFromGlobalJson))
126-
{
127-
var installStateFilePath = Path.Combine(WorkloadInstallType.GetInstallStateFolder(_sdkFeatureBand, _dotnetPath), "default.json");
128-
var installStateContents = InstallStateContents.FromPath(installStateFilePath);
129-
// If install state has pinned workload set or manifest versions, then don't update workloads
130-
if (!string.IsNullOrEmpty(installStateContents.WorkloadVersion) || installStateContents.Manifests != null)
131-
{
132-
// TODO: respect shouldUpdateWorkloads, or figure out update / install manifest difference in InstallingWorkloadCommand
133-
shouldUpdateWorkloads = false;
134-
}
135-
}
136-
137131
Reporter.WriteLine();
138132

139133
DirectoryPath? offlineCache = string.IsNullOrWhiteSpace(_fromCacheOption) ? null : new DirectoryPath(_fromCacheOption);

src/Cli/dotnet/commands/dotnet-workload/install/xlf/LocalizableStrings.cs.xlf

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-workload/install/xlf/LocalizableStrings.de.xlf

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-workload/install/xlf/LocalizableStrings.es.xlf

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-workload/install/xlf/LocalizableStrings.fr.xlf

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-workload/install/xlf/LocalizableStrings.it.xlf

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)