Skip to content

Commit

Permalink
Merge pull request #26796 from dotnet/Jason/Merge604xxToMain
Browse files Browse the repository at this point in the history
Merge branch 'release/6.0.4xx' => 'main'
  • Loading branch information
v-wuzhai authored Aug 3, 2022
2 parents c32edc4 + 1459bf9 commit 9cbd68c
Show file tree
Hide file tree
Showing 33 changed files with 200 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Task<string> GetPackageUrl(PackageId packageId,

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

Task<NuGetVersion> GetLatestPackageVerion(PackageId packageId,
Task<NuGetVersion> GetLatestPackageVersion(PackageId packageId,
PackageSourceLocation packageSourceLocation = null,
bool includePreview = false);
}
Expand Down
16 changes: 10 additions & 6 deletions src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public async Task<string> DownloadPackageAsync(PackageId packageId,
{
CancellationToken cancellationToken = CancellationToken.None;

(var source, var resolvedPackageVersion) = await GetPackageSourceAndVerion(packageId, packageVersion,
(var source, var resolvedPackageVersion) = await GetPackageSourceAndVersion(packageId, packageVersion,
packageSourceLocation, includePreview);

FindPackageByIdResource resource = null;
Expand Down Expand Up @@ -161,9 +161,13 @@ public async Task<string> GetPackageUrl(PackageId packageId,
PackageSourceLocation packageSourceLocation = null,
bool includePreview = false)
{
(var source, var resolvedPackageVersion) = await GetPackageSourceAndVerion(packageId, packageVersion, packageSourceLocation, includePreview);

(var source, var resolvedPackageVersion) = await GetPackageSourceAndVersion(packageId, packageVersion, packageSourceLocation, includePreview);
SourceRepository repository = GetSourceRepository(source);
if (repository.PackageSource.IsLocal)
{
return Path.Combine(repository.PackageSource.Source, $"{packageId}.{resolvedPackageVersion}.nupkg");
}

ServiceIndexResourceV3 serviceIndexResource = repository.GetResourceAsync<ServiceIndexResourceV3>().Result;
IReadOnlyList<Uri> packageBaseAddress =
Expand Down Expand Up @@ -213,7 +217,7 @@ public async Task<IEnumerable<string>> ExtractPackageAsync(string packagePath, D
return allFilesInPackage;
}

private async Task<(PackageSource, NuGetVersion)> GetPackageSourceAndVerion(PackageId packageId,
private async Task<(PackageSource, NuGetVersion)> GetPackageSourceAndVersion(PackageId packageId,
NuGetVersion packageVersion = null,
PackageSourceLocation packageSourceLocation = null,
bool includePreview = false)
Expand Down Expand Up @@ -422,7 +426,7 @@ await Task.WhenAll(
.SelectMany(result => result.foundPackages.Select(package => (result.source, package)));

if (!accumulativeSearchResults.Any())
{
{
throw new NuGetPackageNotFoundException(
string.Format(
LocalizableStrings.IsNotFoundInNuGetFeeds,
Expand Down Expand Up @@ -565,7 +569,7 @@ bool TryGetPackageMetadata(
return (source, foundPackages);
}

public async Task<NuGetVersion> GetLatestPackageVerion(PackageId packageId,
public async Task<NuGetVersion> GetLatestPackageVersion(PackageId packageId,
PackageSourceLocation packageSourceLocation = null,
bool includePreview = false)
{
Expand Down
22 changes: 16 additions & 6 deletions src/Cli/dotnet/commands/InstallingWorkloadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ internal abstract class InstallingWorkloadCommand : WorkloadCommandBase
protected readonly string _downloadToCacheOption;
protected readonly string _dotnetPath;
protected readonly string _userProfileDir;
protected readonly bool _checkIfManifestExist;
protected readonly ReleaseVersion _sdkVersion;
protected readonly SdkFeatureBand _sdkFeatureBand;
protected readonly SdkFeatureBand _installedFeatureBand;
protected readonly string _fromRollbackDefinition;
protected readonly PackageSourceLocation _packageSourceLocation;
protected IWorkloadResolver _workloadResolver;
Expand All @@ -54,7 +56,8 @@ public InstallingWorkloadCommand(
string dotnetDir,
string userProfileDir,
string tempDirPath,
string version)
string version,
string installedFeatureBand = null)
: base(parseResult, reporter: reporter, tempDirPath: tempDirPath, nugetPackageDownloader: nugetPackageDownloader)
{
_printDownloadLinkOnly = parseResult.GetValueForOption(InstallingWorkloadCommandParser.PrintDownloadLinkOnlyOption);
Expand All @@ -63,15 +66,21 @@ public InstallingWorkloadCommand(
_downloadToCacheOption = parseResult.GetValueForOption(InstallingWorkloadCommandParser.DownloadToCacheOption);
_dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath);
_userProfileDir = userProfileDir ?? CliFolderPathCalculator.DotnetUserProfileFolderPath;
_sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.GetValueForOption(InstallingWorkloadCommandParser.VersionOption), version, _dotnetPath, _userProfileDir);
_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(DotnetFiles.VersionFileObject.BuildNumber) : new SdkFeatureBand(installedFeatureBand);

_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, _sdkVersion.ToString(), userProfileDir);

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

_workloadInstallerFromConstructor = workloadInstaller;
_workloadManifestUpdaterFromConstructor = workloadManifestUpdater;
}
Expand Down Expand Up @@ -121,6 +130,7 @@ protected async Task<List<WorkloadDownload>> GetDownloads(IEnumerable<WorkloadId

// Use updated, extracted manifests to resolve packs
var overlayProvider = new TempDirectoryWorkloadManifestProvider(extractedManifestsPath, _sdkVersion.ToString());

var newResolver = _workloadResolver.CreateOverlayResolver(overlayProvider);
_workloadInstaller.ReplaceWorkloadResolver(newResolver);
}
Expand Down Expand Up @@ -153,11 +163,11 @@ protected async Task<List<WorkloadDownload>> GetDownloads(IEnumerable<WorkloadId

protected IEnumerable<WorkloadId> GetInstalledWorkloads(bool fromPreviousSdk)
{
var currentFeatureBand = new SdkFeatureBand(_sdkVersion);
//var currentFeatureBand = new SdkFeatureBand(_installedFeatureBand.ToString());
if (fromPreviousSdk)
{
var priorFeatureBands = _workloadInstaller.GetWorkloadInstallationRecordRepository().GetFeatureBandsWithInstallationRecords()
.Where(featureBand => featureBand.CompareTo(currentFeatureBand) < 0);
.Where(featureBand => featureBand.CompareTo(_installedFeatureBand) < 0);
if (priorFeatureBands.Any())
{
var maxPriorFeatureBand = priorFeatureBands.Max();
Expand All @@ -167,7 +177,7 @@ protected IEnumerable<WorkloadId> GetInstalledWorkloads(bool fromPreviousSdk)
}
else
{
var workloads = _workloadInstaller.GetWorkloadInstallationRecordRepository().GetInstalledWorkloads(currentFeatureBand);
var workloads = _workloadInstaller.GetWorkloadInstallationRecordRepository().GetInstalledWorkloads(_installedFeatureBand);

return workloads ?? Enumerable.Empty<WorkloadId>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void PrintSdkInfo()
if (NewFeatureBandAvailable())
{
_reporter.WriteLine();
// advertise newest feature band
_reporter.WriteLine(string.Format(LocalizableStrings.NewFeatureBandMessage, NewestFeatureBandAvailable()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ public WorkloadDownload(string id, string nuGetPackageId, string nuGetPackageVer
NuGetPackageId = nuGetPackageId;
NuGetPackageVersion = nuGetPackageVersion;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@
<data name="FailedToDownloadPackageManifest" xml:space="preserve">
<value>Failed to download manifest package {0}.</value>
</data>
<data name="FailedToGetPackageManifestUrl" xml:space="preserve">
<value>Failed to resolve manifest package URL {0}.</value>
<data name="ManifestPackageUrlNotResolved" xml:space="preserve">
<value>Manifest package not resolved. Manifest package or URL for {0} doesn't exist.</value>
</data>
<data name="OSDoesNotSupportMsi" xml:space="preserve">
<value>MSI installations are only supported on Windows.</value>
Expand Down Expand Up @@ -342,4 +342,4 @@
<data name="ManifestMsiNotFoundInNuGetPackage" xml:space="preserve">
<value>Manifest MSI not found in NuGet package {0}</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ public WorkloadInstallCommand(
string userProfileDir = null,
string tempDirPath = null,
string version = null,
IReadOnlyCollection<string> workloadIds = null)
IReadOnlyCollection<string> workloadIds = null,
string installedFeatureBand = null)
: base(parseResult, reporter: reporter, workloadResolver: workloadResolver, workloadInstaller: workloadInstaller,
nugetPackageDownloader: nugetPackageDownloader, workloadManifestUpdater: workloadManifestUpdater,
dotnetDir: dotnetDir, userProfileDir: userProfileDir, tempDirPath: tempDirPath, version: version)
dotnetDir: dotnetDir, userProfileDir: userProfileDir, tempDirPath: tempDirPath, version: version, installedFeatureBand: installedFeatureBand)
{
_skipManifestUpdate = parseResult.GetValueForOption(WorkloadInstallCommandParser.SkipManifestUpdateOption);
_workloadIds = workloadIds ?? parseResult.GetValueForArgument(WorkloadInstallCommandParser.WorkloadIdArgument).ToList().AsReadOnly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,35 @@ public async Task<IEnumerable<WorkloadDownload>> GetManifestPackageDownloadsAsyn
{
try
{

var packageId = _workloadManifestInstaller.GetManifestPackageId(new ManifestId(manifest.Id), _sdkFeatureBand);
var latestVersion = await _nugetPackageDownloader.GetLatestPackageVerion(packageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreviews);
downloads.Add(new WorkloadDownload(manifest.Id, packageId.ToString(), latestVersion.ToString()));

bool success;
(success, var latestVersion) = await GetPackageVersion(packageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreviews);
if (success)
{
downloads.Add(new WorkloadDownload(manifest.Id, packageId.ToString(), latestVersion.ToString()));
}
if (!success)
{
var newFeatureBand = new SdkFeatureBand(manifest.ManifestFeatureBand);
var newPackageId = _workloadManifestInstaller.GetManifestPackageId(new ManifestId(manifest.Id), newFeatureBand);

(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));
}
}
catch
{
_reporter.WriteLine(string.Format(LocalizableStrings.FailedToGetPackageManifestUrl, manifest.Id));
_reporter.WriteLine(string.Format(LocalizableStrings.ManifestPackageUrlNotResolved, manifest.Id));
}
}
return downloads;
Expand Down Expand Up @@ -404,7 +426,7 @@ private async Task<bool> NewerManifestPackageExists(ManifestId manifest)
try
{
var currentVersion = NuGetVersion.Parse(_workloadResolver.GetManifestVersion(manifest.ToString()));
var latestVersion = await _nugetPackageDownloader.GetLatestPackageVerion(_workloadManifestInstaller.GetManifestPackageId(manifest, _sdkFeatureBand));
var latestVersion = await _nugetPackageDownloader.GetLatestPackageVersion(_workloadManifestInstaller.GetManifestPackageId(manifest, _sdkFeatureBand));
return latestVersion > currentVersion;
}
catch (Exception)
Expand Down Expand Up @@ -512,7 +534,22 @@ private string GetOfflinePackagePath(SdkFeatureBand sdkFeatureBand, ManifestId m
}
}

private string GetAdvertisingManifestPath(SdkFeatureBand featureBand, ManifestId manifestId) =>
private async Task<(bool, NuGetVersion)> GetPackageVersion(PackageId packageId, PackageSourceLocation packageSourceLocation = null, bool includePreview = false)
{
try
{
var latestVersion = await _nugetPackageDownloader.GetLatestPackageVersion(packageId, packageSourceLocation: _packageSourceLocation, includePreview: includePreview);
return (true, latestVersion);
}
catch (NuGetPackageNotFoundException)
{
return (false, null);
}

}


private string GetAdvertisingManifestPath(SdkFeatureBand featureBand, ManifestId manifestId) =>
Path.Combine(_userProfileDir, "sdk-advertising", featureBand.ToString(), manifestId.ToString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Workloads.Workload.Install
{
internal class WorkloadOptionsExtensions
{
internal static ReleaseVersion GetValidatedSdkVersion(string versionOption, string providedVersion, string dotnetPath, string userProfileDir)
internal static ReleaseVersion GetValidatedSdkVersion(string versionOption, string providedVersion, string dotnetPath, string userProfileDir, bool checkIfFeatureBandManifestsExist)
{

if (string.IsNullOrEmpty(versionOption))
Expand All @@ -27,7 +27,7 @@ internal static ReleaseVersion GetValidatedSdkVersion(string versionOption, stri
else
{
var manifests = new SdkDirectoryWorkloadManifestProvider(dotnetPath, versionOption, userProfileDir).GetManifests();
if (!manifests.Any())
if (!manifests.Any() && checkIfFeatureBandManifestsExist)
{
throw new GracefulException(string.Format(LocalizableStrings.NoManifestsExistForFeatureBand, new SdkFeatureBand(versionOption).ToString()), isUserError: false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@
<target state="translated">Nepovedlo se extrahovat informace z MSI: {0}</target>
<note />
</trans-unit>
<trans-unit id="FailedToGetPackageManifestUrl">
<source>Failed to resolve manifest package URL {0}.</source>
<target state="translated">Nepovedlo se přeložit adresu URL balíčku manifestu {0}.</target>
<note />
</trans-unit>
<trans-unit id="FailedToInstallWorkloadManifest">
<source>Failed to install manifest {0} version {1}: {2}.</source>
<target state="translated">Nepodařilo se nainstalovat manifest {0} verze {1}: {2}.</target>
Expand Down Expand Up @@ -167,6 +162,11 @@
<target state="translated">Instalační služba MSI manifestu se nenašla v balíčku NuGet {0}.</target>
<note />
</trans-unit>
<trans-unit id="ManifestPackageUrlNotResolved">
<source>Manifest package not resolved. Manifest package or URL for {0} doesn't exist.</source>
<target state="new">Manifest package not resolved. Manifest package or URL for {0} doesn't exist.</target>
<note />
</trans-unit>
<trans-unit id="MsiProgressInstall">
<source>Installing {0} </source>
<target state="translated">Instaluje se {0}. </target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@
<target state="translated">Fehler beim Extrahieren von Informationen aus MSI: {0}</target>
<note />
</trans-unit>
<trans-unit id="FailedToGetPackageManifestUrl">
<source>Failed to resolve manifest package URL {0}.</source>
<target state="translated">Fehler beim Auflösen der Manifestpaket-URL {0}.</target>
<note />
</trans-unit>
<trans-unit id="FailedToInstallWorkloadManifest">
<source>Failed to install manifest {0} version {1}: {2}.</source>
<target state="translated">Fehler beim Installieren des Manifests "{0}", Version {1}: {2}.</target>
Expand Down Expand Up @@ -167,6 +162,11 @@
<target state="translated">Manifest-MSI wurde im NuGet-Paket {0} nicht gefunden.</target>
<note />
</trans-unit>
<trans-unit id="ManifestPackageUrlNotResolved">
<source>Manifest package not resolved. Manifest package or URL for {0} doesn't exist.</source>
<target state="new">Manifest package not resolved. Manifest package or URL for {0} doesn't exist.</target>
<note />
</trans-unit>
<trans-unit id="MsiProgressInstall">
<source>Installing {0} </source>
<target state="translated">{0} wird installiert </target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@
<target state="translated">No se pudo extraer información de MSI: {0}</target>
<note />
</trans-unit>
<trans-unit id="FailedToGetPackageManifestUrl">
<source>Failed to resolve manifest package URL {0}.</source>
<target state="translated">No se pudo resolver la dirección URL del paquete de manifiesto {0}.</target>
<note />
</trans-unit>
<trans-unit id="FailedToInstallWorkloadManifest">
<source>Failed to install manifest {0} version {1}: {2}.</source>
<target state="translated">No se pudo instalar el manifiesto {0}, versión {1}: {2}.</target>
Expand Down Expand Up @@ -167,6 +162,11 @@
<target state="translated">No se encontró el MSI del manifiesto en el paquete NuGet {0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestPackageUrlNotResolved">
<source>Manifest package not resolved. Manifest package or URL for {0} doesn't exist.</source>
<target state="new">Manifest package not resolved. Manifest package or URL for {0} doesn't exist.</target>
<note />
</trans-unit>
<trans-unit id="MsiProgressInstall">
<source>Installing {0} </source>
<target state="translated">Instalando {0} </target>
Expand Down
Loading

0 comments on commit 9cbd68c

Please sign in to comment.