Skip to content

Commit 0bc1ff8

Browse files
committed
Fix the workload resolver to use the installed SDK version
Fix to fallback to the manifest sdk version as well.
1 parent ec96199 commit 0bc1ff8

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

src/Cli/dotnet/commands/InstallingWorkloadCommand.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ internal abstract class InstallingWorkloadCommand : WorkloadCommandBase
3737
protected readonly string _userProfileDir;
3838
protected readonly bool _checkIfManifestExist;
3939
protected readonly ReleaseVersion _sdkVersion;
40+
protected readonly ReleaseVersion _installedSdkVersion;
4041
protected readonly SdkFeatureBand _sdkFeatureBand;
4142
protected readonly SdkFeatureBand _installedFeatureBand;
4243
protected readonly string _fromRollbackDefinition;
@@ -70,17 +71,17 @@ public InstallingWorkloadCommand(
7071
_checkIfManifestExist = !(_printDownloadLinkOnly); // don't check for manifest existence when print download link is passed
7172
_sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.GetValueForOption(InstallingWorkloadCommandParser.VersionOption), version, _dotnetPath, _userProfileDir, _checkIfManifestExist);
7273
_sdkFeatureBand = new SdkFeatureBand(_sdkVersion);
73-
74-
_installedFeatureBand = installedFeatureBand == null ? new SdkFeatureBand(Product.Version) : new SdkFeatureBand(installedFeatureBand);
74+
_installedSdkVersion = new ReleaseVersion(version ?? Product.Version);
75+
_installedFeatureBand = new SdkFeatureBand(installedFeatureBand ?? Product.Version);
7576

7677
_fromRollbackDefinition = parseResult.GetValueForOption(InstallingWorkloadCommandParser.FromRollbackFileOption);
7778
var configOption = parseResult.GetValueForOption(InstallingWorkloadCommandParser.ConfigOption);
7879
var sourceOption = parseResult.GetValueForOption(InstallingWorkloadCommandParser.SourceOption);
7980
_packageSourceLocation = string.IsNullOrEmpty(configOption) && (sourceOption == null || !sourceOption.Any()) ? null :
8081
new PackageSourceLocation(string.IsNullOrEmpty(configOption) ? null : new FilePath(configOption), sourceFeedOverrides: sourceOption);
8182

82-
var sdkWorkloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _installedFeatureBand.ToString(), userProfileDir);
83-
_workloadResolver = workloadResolver ?? WorkloadResolver.Create(sdkWorkloadManifestProvider, _dotnetPath, _installedFeatureBand.ToString(), _userProfileDir);
83+
var sdkWorkloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _installedSdkVersion.ToString(), userProfileDir);
84+
_workloadResolver = workloadResolver ?? WorkloadResolver.Create(sdkWorkloadManifestProvider, _dotnetPath, _installedSdkVersion.ToString(), _userProfileDir);
8485

8586
_workloadInstallerFromConstructor = workloadInstaller;
8687
_workloadManifestUpdaterFromConstructor = workloadManifestUpdater;
@@ -109,7 +110,7 @@ protected async Task<List<WorkloadDownload>> GetDownloads(IEnumerable<WorkloadId
109110
folderForManifestDownloads = tempPath.Value;
110111
}
111112

112-
var manifestDownloads = await _workloadManifestUpdater.GetManifestPackageDownloadsAsync(includePreview, new SdkFeatureBand(_sdkVersion), _installedFeatureBand);
113+
var manifestDownloads = await _workloadManifestUpdater.GetManifestPackageDownloadsAsync(includePreview, _sdkFeatureBand, _installedFeatureBand);
113114

114115
if (!manifestDownloads.Any())
115116
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Dictionary<WorkloadId, WorkloadDefinition> Workloads
2323
IEnumerable<ManifestVersionUpdate>
2424
CalculateManifestRollbacks(string rollbackDefinitionFilePath);
2525

26-
Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsync(bool includePreviews, SdkFeatureBand origSdkFeatureBand, SdkFeatureBand installedSdkFeatureBand);
26+
Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsync(bool includePreviews, SdkFeatureBand providedSdkFeatureBand, SdkFeatureBand installedSdkFeatureBand);
2727

2828
IEnumerable<WorkloadId> GetUpdatableWorkloadsToAdvertise(IEnumerable<WorkloadId> installedWorkloads);
2929

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,28 +240,25 @@ public IEnumerable<ManifestVersionUpdate> CalculateManifestRollbacks(string roll
240240
}
241241

242242

243-
public async Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsync(bool includePreviews, SdkFeatureBand origSdkFeatureBand, SdkFeatureBand installedSdkFeatureBand)
243+
public async Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsync(bool includePreviews, SdkFeatureBand providedSdkFeatureBand, SdkFeatureBand installedSdkFeatureBand)
244244
{
245-
var packageIds = GetInstalledManifestIds()
246-
.Select(manifestId => _workloadManifestInstaller.GetManifestPackageId(manifestId, origSdkFeatureBand));
247-
248245
var downloads = new List<WorkloadDownload>();
249246
foreach (var manifest in _workloadResolver.GetInstalledManifests())
250247
{
251248
try
252249
{
253-
254-
var packageId = _workloadManifestInstaller.GetManifestPackageId(new ManifestId(manifest.Id), origSdkFeatureBand);
250+
var packageId = _workloadManifestInstaller.GetManifestPackageId(new ManifestId(manifest.Id), providedSdkFeatureBand);
255251

256252
bool success;
253+
// After checking the --sdk-version, check the current sdk band, and then the manifest band in that order
257254
(success, var latestVersion) = await GetPackageVersion(packageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreviews);
258255
if (success)
259256
{
260257
downloads.Add(new WorkloadDownload(manifest.Id, packageId.ToString(), latestVersion.ToString()));
261258
}
262-
if (!success)
259+
260+
if (!success && !installedSdkFeatureBand.Equals(providedSdkFeatureBand))
263261
{
264-
//var newFeatureBand = new SdkFeatureBand(manifest.ManifestFeatureBand);
265262
var newPackageId = _workloadManifestInstaller.GetManifestPackageId(new ManifestId(manifest.Id), installedSdkFeatureBand);
266263

267264
(success, latestVersion) = await GetPackageVersion(newPackageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreviews);
@@ -271,6 +268,18 @@ public async Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsyn
271268
downloads.Add(new WorkloadDownload(manifest.Id, newPackageId.ToString(), latestVersion.ToString()));
272269
}
273270
}
271+
var fallbackFeatureBand = new SdkFeatureBand(manifest.ManifestFeatureBand);
272+
if (!success && !fallbackFeatureBand.Equals(installedSdkFeatureBand))
273+
{
274+
var newPackageId = _workloadManifestInstaller.GetManifestPackageId(new ManifestId(manifest.Id), fallbackFeatureBand);
275+
276+
(success, latestVersion) = await GetPackageVersion(newPackageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreviews);
277+
278+
if (success)
279+
{
280+
downloads.Add(new WorkloadDownload(manifest.Id, newPackageId.ToString(), latestVersion.ToString()));
281+
}
282+
}
274283
if (!success)
275284
{
276285
_reporter.WriteLine(string.Format(LocalizableStrings.ManifestPackageUrlNotResolved, packageId));

src/Tests/dotnet-workload-install.Tests/MockWorkloadManifestUpdater.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Task UpdateAdvertisingManifestsAsync(bool includePreview, DirectoryPath?
4343
return _manifestUpdates;
4444
}
4545

46-
public Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsync(bool includePreviews, SdkFeatureBand origSdkFeatureBand, SdkFeatureBand installedSdkFeatureBand)
46+
public Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsync(bool includePreviews, SdkFeatureBand providedSdkFeatureBand, SdkFeatureBand installedSdkFeatureBand)
4747
{
4848
GetManifestPackageDownloadsCallCount++;
4949
return Task.FromResult<IEnumerable<WorkloadDownload>>(new List<WorkloadDownload>()

0 commit comments

Comments
 (0)