Skip to content

Commit

Permalink
Fix the workload resolver to use the installed SDK version
Browse files Browse the repository at this point in the history
Fix to fallback to the manifest sdk version as well.
  • Loading branch information
marcpopMSFT committed Aug 9, 2022
1 parent ec96199 commit 0bc1ff8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/Cli/dotnet/commands/InstallingWorkloadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal abstract class InstallingWorkloadCommand : WorkloadCommandBase
protected readonly string _userProfileDir;
protected readonly bool _checkIfManifestExist;
protected readonly ReleaseVersion _sdkVersion;
protected readonly ReleaseVersion _installedSdkVersion;
protected readonly SdkFeatureBand _sdkFeatureBand;
protected readonly SdkFeatureBand _installedFeatureBand;
protected readonly string _fromRollbackDefinition;
Expand Down Expand Up @@ -70,17 +71,17 @@ public InstallingWorkloadCommand(
_checkIfManifestExist = !(_printDownloadLinkOnly); // don't check for manifest existence when print download link is passed
_sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.GetValueForOption(InstallingWorkloadCommandParser.VersionOption), version, _dotnetPath, _userProfileDir, _checkIfManifestExist);
_sdkFeatureBand = new SdkFeatureBand(_sdkVersion);

_installedFeatureBand = installedFeatureBand == null ? new SdkFeatureBand(Product.Version) : new SdkFeatureBand(installedFeatureBand);
_installedSdkVersion = new ReleaseVersion(version ?? Product.Version);
_installedFeatureBand = new SdkFeatureBand(installedFeatureBand ?? Product.Version);

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

var sdkWorkloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _installedFeatureBand.ToString(), userProfileDir);
_workloadResolver = workloadResolver ?? WorkloadResolver.Create(sdkWorkloadManifestProvider, _dotnetPath, _installedFeatureBand.ToString(), _userProfileDir);
var sdkWorkloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _installedSdkVersion.ToString(), userProfileDir);
_workloadResolver = workloadResolver ?? WorkloadResolver.Create(sdkWorkloadManifestProvider, _dotnetPath, _installedSdkVersion.ToString(), _userProfileDir);

_workloadInstallerFromConstructor = workloadInstaller;
_workloadManifestUpdaterFromConstructor = workloadManifestUpdater;
Expand Down Expand Up @@ -109,7 +110,7 @@ protected async Task<List<WorkloadDownload>> GetDownloads(IEnumerable<WorkloadId
folderForManifestDownloads = tempPath.Value;
}

var manifestDownloads = await _workloadManifestUpdater.GetManifestPackageDownloadsAsync(includePreview, new SdkFeatureBand(_sdkVersion), _installedFeatureBand);
var manifestDownloads = await _workloadManifestUpdater.GetManifestPackageDownloadsAsync(includePreview, _sdkFeatureBand, _installedFeatureBand);

if (!manifestDownloads.Any())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Dictionary<WorkloadId, WorkloadDefinition> Workloads
IEnumerable<ManifestVersionUpdate>
CalculateManifestRollbacks(string rollbackDefinitionFilePath);

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,28 +240,25 @@ public IEnumerable<ManifestVersionUpdate> CalculateManifestRollbacks(string roll
}


public async Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsync(bool includePreviews, SdkFeatureBand origSdkFeatureBand, SdkFeatureBand installedSdkFeatureBand)
public async Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsync(bool includePreviews, SdkFeatureBand providedSdkFeatureBand, SdkFeatureBand installedSdkFeatureBand)
{
var packageIds = GetInstalledManifestIds()
.Select(manifestId => _workloadManifestInstaller.GetManifestPackageId(manifestId, origSdkFeatureBand));

var downloads = new List<WorkloadDownload>();
foreach (var manifest in _workloadResolver.GetInstalledManifests())
{
try
{

var packageId = _workloadManifestInstaller.GetManifestPackageId(new ManifestId(manifest.Id), origSdkFeatureBand);
var packageId = _workloadManifestInstaller.GetManifestPackageId(new ManifestId(manifest.Id), providedSdkFeatureBand);

bool success;
// After checking the --sdk-version, check the current sdk band, and then the manifest band in that order
(success, var latestVersion) = await GetPackageVersion(packageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreviews);
if (success)
{
downloads.Add(new WorkloadDownload(manifest.Id, packageId.ToString(), latestVersion.ToString()));
}
if (!success)

if (!success && !installedSdkFeatureBand.Equals(providedSdkFeatureBand))
{
//var newFeatureBand = new SdkFeatureBand(manifest.ManifestFeatureBand);
var newPackageId = _workloadManifestInstaller.GetManifestPackageId(new ManifestId(manifest.Id), installedSdkFeatureBand);

(success, latestVersion) = await GetPackageVersion(newPackageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreviews);
Expand All @@ -271,6 +268,18 @@ public async Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsyn
downloads.Add(new WorkloadDownload(manifest.Id, newPackageId.ToString(), latestVersion.ToString()));
}
}
var fallbackFeatureBand = new SdkFeatureBand(manifest.ManifestFeatureBand);
if (!success && !fallbackFeatureBand.Equals(installedSdkFeatureBand))
{
var newPackageId = _workloadManifestInstaller.GetManifestPackageId(new ManifestId(manifest.Id), fallbackFeatureBand);

(success, latestVersion) = await GetPackageVersion(newPackageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreviews);

if (success)
{
downloads.Add(new WorkloadDownload(manifest.Id, newPackageId.ToString(), latestVersion.ToString()));
}
}
if (!success)
{
_reporter.WriteLine(string.Format(LocalizableStrings.ManifestPackageUrlNotResolved, packageId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Task UpdateAdvertisingManifestsAsync(bool includePreview, DirectoryPath?
return _manifestUpdates;
}

public Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsync(bool includePreviews, SdkFeatureBand origSdkFeatureBand, SdkFeatureBand installedSdkFeatureBand)
public Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsync(bool includePreviews, SdkFeatureBand providedSdkFeatureBand, SdkFeatureBand installedSdkFeatureBand)
{
GetManifestPackageDownloadsCallCount++;
return Task.FromResult<IEnumerable<WorkloadDownload>>(new List<WorkloadDownload>()
Expand Down

0 comments on commit 0bc1ff8

Please sign in to comment.