Skip to content

Commit 52a29bc

Browse files
authored
Merge pull request #26369 from gkulin/downloadLinkChange
Allow dotnet workload update print-download-link-only to use fallback and work with prior SDK versions
2 parents 4b0c215 + 01d1e6f commit 52a29bc

34 files changed

+203
-144
lines changed

src/Cli/dotnet/NugetPackageDownloader/INuGetPackageDownloader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Task<string> GetPackageUrl(PackageId packageId,
2424

2525
Task<IEnumerable<string>> ExtractPackageAsync(string packagePath, DirectoryPath targetFolder);
2626

27-
Task<NuGetVersion> GetLatestPackageVerion(PackageId packageId,
27+
Task<NuGetVersion> GetLatestPackageVersion(PackageId packageId,
2828
PackageSourceLocation packageSourceLocation = null,
2929
bool includePreview = false);
3030
}

src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public async Task<string> DownloadPackageAsync(PackageId packageId,
8686
{
8787
CancellationToken cancellationToken = CancellationToken.None;
8888

89-
(var source, var resolvedPackageVersion) = await GetPackageSourceAndVerion(packageId, packageVersion,
89+
(var source, var resolvedPackageVersion) = await GetPackageSourceAndVersion(packageId, packageVersion,
9090
packageSourceLocation, includePreview);
9191

9292
FindPackageByIdResource resource = null;
@@ -162,9 +162,13 @@ public async Task<string> GetPackageUrl(PackageId packageId,
162162
PackageSourceLocation packageSourceLocation = null,
163163
bool includePreview = false)
164164
{
165-
(var source, var resolvedPackageVersion) = await GetPackageSourceAndVerion(packageId, packageVersion, packageSourceLocation, includePreview);
166-
165+
(var source, var resolvedPackageVersion) = await GetPackageSourceAndVersion(packageId, packageVersion, packageSourceLocation, includePreview);
166+
167167
SourceRepository repository = GetSourceRepository(source);
168+
if (repository.PackageSource.IsLocal)
169+
{
170+
return Path.Combine(repository.PackageSource.Source, $"{packageId}.{resolvedPackageVersion}.nupkg");
171+
}
168172

169173
ServiceIndexResourceV3 serviceIndexResource = repository.GetResourceAsync<ServiceIndexResourceV3>().Result;
170174
IReadOnlyList<Uri> packageBaseAddress =
@@ -214,7 +218,7 @@ public async Task<IEnumerable<string>> ExtractPackageAsync(string packagePath, D
214218
return allFilesInPackage;
215219
}
216220

217-
private async Task<(PackageSource, NuGetVersion)> GetPackageSourceAndVerion(PackageId packageId,
221+
private async Task<(PackageSource, NuGetVersion)> GetPackageSourceAndVersion(PackageId packageId,
218222
NuGetVersion packageVersion = null,
219223
PackageSourceLocation packageSourceLocation = null,
220224
bool includePreview = false)
@@ -423,7 +427,7 @@ await Task.WhenAll(
423427
.SelectMany(result => result.foundPackages.Select(package => (result.source, package)));
424428

425429
if (!accumulativeSearchResults.Any())
426-
{
430+
{
427431
throw new NuGetPackageNotFoundException(
428432
string.Format(
429433
LocalizableStrings.IsNotFoundInNuGetFeeds,
@@ -566,7 +570,7 @@ bool TryGetPackageMetadata(
566570
return (source, foundPackages);
567571
}
568572

569-
public async Task<NuGetVersion> GetLatestPackageVerion(PackageId packageId,
573+
public async Task<NuGetVersion> GetLatestPackageVersion(PackageId packageId,
570574
PackageSourceLocation packageSourceLocation = null,
571575
bool includePreview = false)
572576
{

src/Cli/dotnet/commands/InstallingWorkloadCommand.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ internal abstract class InstallingWorkloadCommand : WorkloadCommandBase
3434
protected readonly string _downloadToCacheOption;
3535
protected readonly string _dotnetPath;
3636
protected readonly string _userProfileDir;
37+
protected readonly bool _checkIfManifestExist;
3738
protected readonly ReleaseVersion _sdkVersion;
3839
protected readonly SdkFeatureBand _sdkFeatureBand;
40+
protected readonly SdkFeatureBand _installedFeatureBand;
3941
protected readonly string _fromRollbackDefinition;
4042
protected readonly PackageSourceLocation _packageSourceLocation;
4143
protected IWorkloadResolver _workloadResolver;
@@ -54,7 +56,8 @@ public InstallingWorkloadCommand(
5456
string dotnetDir,
5557
string userProfileDir,
5658
string tempDirPath,
57-
string version)
59+
string version,
60+
string installedFeatureBand = null)
5861
: base(parseResult, reporter: reporter, tempDirPath: tempDirPath, nugetPackageDownloader: nugetPackageDownloader)
5962
{
6063
_printDownloadLinkOnly = parseResult.GetValueForOption(InstallingWorkloadCommandParser.PrintDownloadLinkOnlyOption);
@@ -63,15 +66,21 @@ public InstallingWorkloadCommand(
6366
_downloadToCacheOption = parseResult.GetValueForOption(InstallingWorkloadCommandParser.DownloadToCacheOption);
6467
_dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath);
6568
_userProfileDir = userProfileDir ?? CliFolderPathCalculator.DotnetUserProfileFolderPath;
66-
_sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.GetValueForOption(InstallingWorkloadCommandParser.VersionOption), version, _dotnetPath, _userProfileDir);
69+
_checkIfManifestExist = !(_printDownloadLinkOnly); // don't check for manifest existence when print download link is passed
70+
_sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.GetValueForOption(InstallingWorkloadCommandParser.VersionOption), version, _dotnetPath, _userProfileDir, _checkIfManifestExist);
6771
_sdkFeatureBand = new SdkFeatureBand(_sdkVersion);
72+
73+
_installedFeatureBand = installedFeatureBand == null ? new SdkFeatureBand(DotnetFiles.VersionFileObject.BuildNumber) : new SdkFeatureBand(installedFeatureBand);
74+
6875
_fromRollbackDefinition = parseResult.GetValueForOption(InstallingWorkloadCommandParser.FromRollbackFileOption);
6976
var configOption = parseResult.GetValueForOption(InstallingWorkloadCommandParser.ConfigOption);
7077
var sourceOption = parseResult.GetValueForOption(InstallingWorkloadCommandParser.SourceOption);
7178
_packageSourceLocation = string.IsNullOrEmpty(configOption) && (sourceOption == null || !sourceOption.Any()) ? null :
7279
new PackageSourceLocation(string.IsNullOrEmpty(configOption) ? null : new FilePath(configOption), sourceFeedOverrides: sourceOption);
73-
var sdkWorkloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _sdkVersion.ToString(), userProfileDir);
80+
81+
var sdkWorkloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _installedFeatureBand.ToString(), userProfileDir);
7482
_workloadResolver = workloadResolver ?? WorkloadResolver.Create(sdkWorkloadManifestProvider, _dotnetPath, _sdkVersion.ToString(), _userProfileDir);
83+
7584
_workloadInstallerFromConstructor = workloadInstaller;
7685
_workloadManifestUpdaterFromConstructor = workloadManifestUpdater;
7786
}
@@ -121,6 +130,7 @@ protected async Task<List<WorkloadDownload>> GetDownloads(IEnumerable<WorkloadId
121130

122131
// Use updated, extracted manifests to resolve packs
123132
var overlayProvider = new TempDirectoryWorkloadManifestProvider(extractedManifestsPath, _sdkVersion.ToString());
133+
124134
var newResolver = _workloadResolver.CreateOverlayResolver(overlayProvider);
125135
_workloadInstaller.ReplaceWorkloadResolver(newResolver);
126136
}
@@ -153,11 +163,11 @@ protected async Task<List<WorkloadDownload>> GetDownloads(IEnumerable<WorkloadId
153163

154164
protected IEnumerable<WorkloadId> GetInstalledWorkloads(bool fromPreviousSdk)
155165
{
156-
var currentFeatureBand = new SdkFeatureBand(_sdkVersion);
166+
//var currentFeatureBand = new SdkFeatureBand(_installedFeatureBand.ToString());
157167
if (fromPreviousSdk)
158168
{
159169
var priorFeatureBands = _workloadInstaller.GetWorkloadInstallationRecordRepository().GetFeatureBandsWithInstallationRecords()
160-
.Where(featureBand => featureBand.CompareTo(currentFeatureBand) < 0);
170+
.Where(featureBand => featureBand.CompareTo(_installedFeatureBand) < 0);
161171
if (priorFeatureBands.Any())
162172
{
163173
var maxPriorFeatureBand = priorFeatureBands.Max();
@@ -167,7 +177,7 @@ protected IEnumerable<WorkloadId> GetInstalledWorkloads(bool fromPreviousSdk)
167177
}
168178
else
169179
{
170-
var workloads = _workloadInstaller.GetWorkloadInstallationRecordRepository().GetInstalledWorkloads(currentFeatureBand);
180+
var workloads = _workloadInstaller.GetWorkloadInstallationRecordRepository().GetInstalledWorkloads(_installedFeatureBand);
171181

172182
return workloads ?? Enumerable.Empty<WorkloadId>();
173183
}

src/Cli/dotnet/commands/dotnet-sdk/check/SdkOutputWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public void PrintSdkInfo()
3636
if (NewFeatureBandAvailable())
3737
{
3838
_reporter.WriteLine();
39+
// advertise newest feature band
3940
_reporter.WriteLine(string.Format(LocalizableStrings.NewFeatureBandMessage, NewestFeatureBandAvailable()));
4041
}
4142
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ public WorkloadDownload(string id, string nuGetPackageId, string nuGetPackageVer
6666
NuGetPackageId = nuGetPackageId;
6767
NuGetPackageVersion = nuGetPackageVersion;
6868
}
69+
6970
}
7071
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@
255255
<data name="FailedToDownloadPackageManifest" xml:space="preserve">
256256
<value>Failed to download manifest package {0}.</value>
257257
</data>
258-
<data name="FailedToGetPackageManifestUrl" xml:space="preserve">
259-
<value>Failed to resolve manifest package URL {0}.</value>
258+
<data name="ManifestPackageUrlNotResolved" xml:space="preserve">
259+
<value>Manifest package not resolved. Manifest package or URL for {0} doesn't exist.</value>
260260
</data>
261261
<data name="OSDoesNotSupportMsi" xml:space="preserve">
262262
<value>MSI installations are only supported on Windows.</value>
@@ -342,4 +342,4 @@
342342
<data name="ManifestMsiNotFoundInNuGetPackage" xml:space="preserve">
343343
<value>Manifest MSI not found in NuGet package {0}</value>
344344
</data>
345-
</root>
345+
</root>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ public WorkloadInstallCommand(
4141
string userProfileDir = null,
4242
string tempDirPath = null,
4343
string version = null,
44-
IReadOnlyCollection<string> workloadIds = null)
44+
IReadOnlyCollection<string> workloadIds = null,
45+
string installedFeatureBand = null)
4546
: base(parseResult, reporter: reporter, workloadResolver: workloadResolver, workloadInstaller: workloadInstaller,
4647
nugetPackageDownloader: nugetPackageDownloader, workloadManifestUpdater: workloadManifestUpdater,
47-
dotnetDir: dotnetDir, userProfileDir: userProfileDir, tempDirPath: tempDirPath, version: version)
48+
dotnetDir: dotnetDir, userProfileDir: userProfileDir, tempDirPath: tempDirPath, version: version, installedFeatureBand: installedFeatureBand)
4849
{
4950
_skipManifestUpdate = parseResult.GetValueForOption(WorkloadInstallCommandParser.SkipManifestUpdateOption);
5051
_workloadIds = workloadIds ?? parseResult.GetValueForArgument(WorkloadInstallCommandParser.WorkloadIdArgument).ToList().AsReadOnly();

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

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,35 @@ public async Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsyn
249249
{
250250
try
251251
{
252+
252253
var packageId = _workloadManifestInstaller.GetManifestPackageId(new ManifestId(manifest.Id), _sdkFeatureBand);
253-
var latestVersion = await _nugetPackageDownloader.GetLatestPackageVerion(packageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreviews);
254-
downloads.Add(new WorkloadDownload(manifest.Id, packageId.ToString(), latestVersion.ToString()));
254+
255+
bool success;
256+
(success, var latestVersion) = await GetPackageVersion(packageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreviews);
257+
if (success)
258+
{
259+
downloads.Add(new WorkloadDownload(manifest.Id, packageId.ToString(), latestVersion.ToString()));
260+
}
261+
if (!success)
262+
{
263+
var newFeatureBand = new SdkFeatureBand(manifest.ManifestFeatureBand);
264+
var newPackageId = _workloadManifestInstaller.GetManifestPackageId(new ManifestId(manifest.Id), newFeatureBand);
265+
266+
(success, latestVersion) = await GetPackageVersion(newPackageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreviews);
267+
268+
if (success)
269+
{
270+
downloads.Add(new WorkloadDownload(manifest.Id, newPackageId.ToString(), latestVersion.ToString()));
271+
}
272+
}
273+
if (!success)
274+
{
275+
_reporter.WriteLine(string.Format(LocalizableStrings.ManifestPackageUrlNotResolved, packageId));
276+
}
255277
}
256278
catch
257279
{
258-
_reporter.WriteLine(string.Format(LocalizableStrings.FailedToGetPackageManifestUrl, manifest.Id));
280+
_reporter.WriteLine(string.Format(LocalizableStrings.ManifestPackageUrlNotResolved, manifest.Id));
259281
}
260282
}
261283
return downloads;
@@ -404,7 +426,7 @@ private async Task<bool> NewerManifestPackageExists(ManifestId manifest)
404426
try
405427
{
406428
var currentVersion = NuGetVersion.Parse(_workloadResolver.GetManifestVersion(manifest.ToString()));
407-
var latestVersion = await _nugetPackageDownloader.GetLatestPackageVerion(_workloadManifestInstaller.GetManifestPackageId(manifest, _sdkFeatureBand));
429+
var latestVersion = await _nugetPackageDownloader.GetLatestPackageVersion(_workloadManifestInstaller.GetManifestPackageId(manifest, _sdkFeatureBand));
408430
return latestVersion > currentVersion;
409431
}
410432
catch (Exception)
@@ -512,7 +534,22 @@ private string GetOfflinePackagePath(SdkFeatureBand sdkFeatureBand, ManifestId m
512534
}
513535
}
514536

515-
private string GetAdvertisingManifestPath(SdkFeatureBand featureBand, ManifestId manifestId) =>
537+
private async Task<(bool, NuGetVersion)> GetPackageVersion(PackageId packageId, PackageSourceLocation packageSourceLocation = null, bool includePreview = false)
538+
{
539+
try
540+
{
541+
var latestVersion = await _nugetPackageDownloader.GetLatestPackageVersion(packageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreview);
542+
return (true, latestVersion);
543+
}
544+
catch (NuGetPackageNotFoundException)
545+
{
546+
return (false, null);
547+
}
548+
549+
}
550+
551+
552+
private string GetAdvertisingManifestPath(SdkFeatureBand featureBand, ManifestId manifestId) =>
516553
Path.Combine(_userProfileDir, "sdk-advertising", featureBand.ToString(), manifestId.ToString());
517554
}
518555
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Workloads.Workload.Install
1717
{
1818
internal class WorkloadOptionsExtensions
1919
{
20-
internal static ReleaseVersion GetValidatedSdkVersion(string versionOption, string providedVersion, string dotnetPath, string userProfileDir)
20+
internal static ReleaseVersion GetValidatedSdkVersion(string versionOption, string providedVersion, string dotnetPath, string userProfileDir, bool checkIfFeatureBandManifestsExist)
2121
{
2222

2323
if (string.IsNullOrEmpty(versionOption))
@@ -27,9 +27,9 @@ internal static ReleaseVersion GetValidatedSdkVersion(string versionOption, stri
2727
else
2828
{
2929
var manifests = new SdkDirectoryWorkloadManifestProvider(dotnetPath, versionOption, userProfileDir).GetManifests();
30-
if (!manifests.Any())
30+
if (!manifests.Any() && checkIfFeatureBandManifestsExist)
3131
{
32-
throw new GracefulException(string.Format(LocalizableStrings.NoManifestsExistForFeatureBand, versionOption), isUserError: false);
32+
throw new GracefulException(string.Format(LocalizableStrings.NoManifestsExistForFeatureBand, versionOption), isUserError: false);
3333
}
3434
try
3535
{

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@
6767
<target state="translated">Nepovedlo se extrahovat informace z MSI: {0}</target>
6868
<note />
6969
</trans-unit>
70-
<trans-unit id="FailedToGetPackageManifestUrl">
71-
<source>Failed to resolve manifest package URL {0}.</source>
72-
<target state="translated">Nepovedlo se přeložit adresu URL balíčku manifestu {0}.</target>
73-
<note />
74-
</trans-unit>
7570
<trans-unit id="FailedToInstallWorkloadManifest">
7671
<source>Failed to install manifest {0} version {1}: {2}.</source>
7772
<target state="translated">Nepodařilo se nainstalovat manifest {0} verze {1}: {2}.</target>
@@ -167,6 +162,11 @@
167162
<target state="translated">Instalační služba MSI manifestu se nenašla v balíčku NuGet {0}.</target>
168163
<note />
169164
</trans-unit>
165+
<trans-unit id="ManifestPackageUrlNotResolved">
166+
<source>Manifest package not resolved. Manifest package or URL for {0} doesn't exist.</source>
167+
<target state="new">Manifest package not resolved. Manifest package or URL for {0} doesn't exist.</target>
168+
<note />
169+
</trans-unit>
170170
<trans-unit id="MsiProgressInstall">
171171
<source>Installing {0} </source>
172172
<target state="translated">Instaluje se {0}. </target>

0 commit comments

Comments
 (0)