Skip to content

Commit d6f4293

Browse files
committed
Fix some cases of pinning / unpinning workload version in global install state
1 parent 2438d99 commit d6f4293

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

src/Cli/dotnet/commands/InstallingWorkloadCommand.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected void UpdateWorkloadManifests(ITransactionContext context, DirectoryPat
165165
}
166166

167167
string resolvedWorkloadSetVersion = _workloadSetVersionFromGlobalJson ??_workloadSetVersionFromCommandLine;
168-
if (string.IsNullOrWhiteSpace(resolvedWorkloadSetVersion) && !UseRollback /* TODO && !specifiedWorkloadManifestsInInstallState */)
168+
if (string.IsNullOrWhiteSpace(resolvedWorkloadSetVersion) && !UseRollback)
169169
{
170170
_workloadManifestUpdater.UpdateAdvertisingManifestsAsync(_includePreviews, updateUsingWorkloadSets, offlineCache).Wait();
171171
if (updateUsingWorkloadSets)
@@ -207,15 +207,17 @@ protected void UpdateWorkloadManifests(ITransactionContext context, DirectoryPat
207207
{
208208
_workloadInstaller.SaveInstallStateManifestVersions(_sdkFeatureBand, GetInstallStateContents(manifestsToUpdate));
209209
}
210+
else if (SpecifiedWorkloadSetVersionOnCommandLine)
211+
{
212+
_workloadInstaller.AdjustWorkloadSetInInstallState(_sdkFeatureBand, resolvedWorkloadSetVersion);
213+
}
210214
else if (this is WorkloadUpdateCommand)
211215
{
212-
// For workload updates, if you don't specify a rollback file, then we should update to a new version of the manifests or workload set, and
216+
// For workload updates, if you don't specify a rollback file, or a workload version then we should update to a new version of the manifests or workload set, and
213217
// should remove the install state that pins to the other version
214-
// TODO: Do we need to do something similar if the workload set version is pinned in the install state?
215218
_workloadInstaller.RemoveManifestsFromInstallState(_sdkFeatureBand);
219+
_workloadInstaller.AdjustWorkloadSetInInstallState(_sdkFeatureBand, null);
216220
}
217-
218-
_workloadInstaller.AdjustWorkloadSetInInstallState(_sdkFeatureBand, resolvedWorkloadSetVersion);
219221
}
220222

221223
_workloadResolver.RefreshWorkloadManifests();

src/Tests/dotnet-MsiInstallation.Tests/WorkloadSetTests.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ public void UpdateWithWorkloadSets()
8181
AddNuGetSource(@"c:\SdkTesting\WorkloadSets");
8282

8383
VM.CreateRunCommand("dotnet", "workload", "update")
84-
.Execute()
85-
.Should()
86-
.Pass();
84+
.Execute().Should().Pass();
8785

8886
var newRollback = GetRollback();
8987

@@ -174,7 +172,6 @@ public void UpdateToUnavailableWorkloadSetVersion()
174172
GetWorkloadVersion().Should().Be(workloadVersionBeforeUpdate);
175173
}
176174

177-
178175
[Fact]
179176
public void UpdateWorkloadSetWithoutAvailableManifests()
180177
{
@@ -220,6 +217,32 @@ public void UpdateToWorkloadSetVersionWithManifestsNotAvailable()
220217
GetWorkloadVersion().Should().Be(workloadVersionBeforeUpdate);
221218
}
222219

220+
[Fact]
221+
public void UpdateShouldNotPinWorkloadSet()
222+
{
223+
InstallSdk();
224+
UpdateAndSwitchToWorkloadSetMode(out _, out _);
225+
226+
AddNuGetSource(@"c:\SdkTesting\WorkloadSets");
227+
228+
// Rename latest workload set so it won't be installed
229+
VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.8.0.300-preview.*.24217.2.nupkg", $"Microsoft.NET.Workloads.8.0.300-preview.*.24217.2.bak")
230+
.Execute().Should().Pass();
231+
232+
VM.CreateRunCommand("dotnet", "workload", "update")
233+
.Execute().Should().Pass();
234+
235+
GetWorkloadVersion().Should().Be("8.0.300-preview.0.24178.1");
236+
237+
// Bring latest workload set version back, so installing workload should update to it
238+
VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.8.0.300-preview.*.24217.2.bak", $"Microsoft.NET.Workloads.8.0.300-preview.*.24217.2.nupkg")
239+
.Execute().Should().Pass();
240+
241+
InstallWorkload("aspire", skipManifestUpdate: false);
242+
243+
GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2");
244+
}
245+
223246
[Fact]
224247
public void WorkloadSetInstallationRecordIsWrittenCorrectly()
225248
{

0 commit comments

Comments
 (0)