Skip to content

Commit

Permalink
Permit loose manifest priority
Browse files Browse the repository at this point in the history
  • Loading branch information
Forgind committed Jul 9, 2024
1 parent 4f75e80 commit 769b812
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,28 +169,24 @@ bool TryGetWorkloadSet(string workloadSetVersion, out WorkloadSet? workloadSet)
}
}

_installStateFilePath = Path.Combine(WorkloadInstallType.GetInstallStateFolder(_sdkVersionBand, _sdkRootPath), "default.json");
var installState = InstallStateContents.FromPath(_installStateFilePath);
if (_workloadSet is null)
{
var installStateFilePath = Path.Combine(WorkloadInstallType.GetInstallStateFolder(_sdkVersionBand, _sdkRootPath), "default.json");
if (File.Exists(installStateFilePath))
if (!string.IsNullOrEmpty(installState.WorkloadVersion))
{
var installState = InstallStateContents.FromPath(installStateFilePath);
if (!string.IsNullOrEmpty(installState.WorkloadVersion))
if (!TryGetWorkloadSet(installState.WorkloadVersion!, out _workloadSet))
{
if (!TryGetWorkloadSet(installState.WorkloadVersion!, out _workloadSet))
{
throw new FileNotFoundException(string.Format(Strings.WorkloadVersionFromInstallStateNotFound, installState.WorkloadVersion, installStateFilePath));
}
throw new FileNotFoundException(string.Format(Strings.WorkloadVersionFromInstallStateNotFound, installState.WorkloadVersion, _installStateFilePath));
}

// Note: It is possible here to have both a workload set and loose manifests listed in the install state. This might happen if there is a
// third-party workload manifest installed that's not part of the workload set
_manifestsFromInstallState = installState.Manifests is null ? null : WorkloadSet.FromDictionaryForJson(installState.Manifests, _sdkVersionBand);
_installStateFilePath = installStateFilePath;
}

// Note: It is possible here to have both a workload set and loose manifests listed in the install state. This might happen if there is a
// third-party workload manifest installed that's not part of the workload set
_manifestsFromInstallState = installState.Manifests is null ? null : WorkloadSet.FromDictionaryForJson(installState.Manifests, _sdkVersionBand);
}

if (_workloadSet == null && availableWorkloadSets.Any())
if (_workloadSet == null && installState.UseWorkloadSets == true && availableWorkloadSets.Any())
{
var maxWorkloadSetVersion = availableWorkloadSets.Keys.Aggregate((s1, s2) => VersionCompare(s1, s2) >= 0 ? s1 : s2);
_workloadSet = availableWorkloadSets[maxWorkloadSetVersion.ToString()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Workloads.Workload;
using Microsoft.NET.Sdk.Localization;
using Microsoft.NET.Sdk.WorkloadManifestReader;

Expand Down Expand Up @@ -418,6 +419,13 @@ public void WorkloadSetCanIncludeMultipleJsonFiles()
CreateMockManifest(_manifestRoot, "8.0.200", "android", "33.0.2-rc.1", true);
CreateMockManifest(_manifestRoot, "8.0.200", "android", "33.0.2", true);

// To prepare the resolver to work with workload sets, we need to specify 'workload sets' in the install state file.
var installStateLocation = WorkloadInstallType.GetInstallStateFolder(new SdkFeatureBand("8.0.200"), Path.GetDirectoryName(_manifestRoot)!);
var installStateFilePath = Path.Combine(installStateLocation, "default.json");
var installState = InstallStateContents.FromPath(installStateFilePath);
installState.UseWorkloadSets = true;
Directory.CreateDirectory(installStateLocation);
File.WriteAllText(installStateFilePath, installState.ToString());

var workloadSetDirectory = Path.Combine(_manifestRoot, "8.0.200", "workloadsets", "8.0.200");
Directory.CreateDirectory(workloadSetDirectory);
Expand Down Expand Up @@ -1254,6 +1262,14 @@ private void CreateMockManifest(string manifestRoot, string featureBand, string

private void CreateMockWorkloadSet(string manifestRoot, string featureBand, string workloadSetVersion, string workloadSetContents)
{
// To prepare the resolver to work with workload sets, we need to specify 'workload sets' in the install state file.
var installStateLocation = WorkloadInstallType.GetInstallStateFolder(new SdkFeatureBand(featureBand), Path.GetDirectoryName(manifestRoot)!);
var installStateFilePath = Path.Combine(installStateLocation, "default.json");
var installState = InstallStateContents.FromPath(installStateFilePath);
installState.UseWorkloadSets = true;
Directory.CreateDirectory(installStateLocation);
File.WriteAllText(installStateFilePath, installState.ToString());

var workloadSetDirectory = Path.Combine(manifestRoot, featureBand, "workloadsets", workloadSetVersion);
if (!Directory.Exists(workloadSetDirectory))
{
Expand Down

0 comments on commit 769b812

Please sign in to comment.