|
4 | 4 | using System.Diagnostics.CodeAnalysis;
|
5 | 5 | using System.Runtime.CompilerServices;
|
6 | 6 | using Microsoft.DotNet.Cli;
|
| 7 | +using Microsoft.DotNet.Workloads.Workload; |
7 | 8 | using Microsoft.NET.Sdk.Localization;
|
8 | 9 | using Microsoft.NET.Sdk.WorkloadManifestReader;
|
9 | 10 |
|
@@ -31,6 +32,40 @@ void Initialize(string featureBand = "5.0.100", [CallerMemberName] string? testN
|
31 | 32 | Directory.CreateDirectory(_manifestVersionBandDirectory);
|
32 | 33 | }
|
33 | 34 |
|
| 35 | + [Theory] |
| 36 | + [InlineData(true)] |
| 37 | + [InlineData(false)] |
| 38 | + public void ItShouldPrioritizeInstallStateOverWorkloadSetUnlessSpecified(bool preferWorkloadSet) |
| 39 | + { |
| 40 | + Initialize(); |
| 41 | + |
| 42 | + CreateMockManifest(_manifestRoot, "8.0.400", "ios", "11.0.2", true); |
| 43 | + CreateMockManifest(_manifestRoot, "8.0.400", "ios", "11.0.6", true); |
| 44 | + CreateMockWorkloadSet(_manifestRoot, "8.0.400", "8.0.400", @" |
| 45 | + { |
| 46 | + ""ios"": ""11.0.2/8.0.400"" |
| 47 | + } |
| 48 | + "); |
| 49 | + |
| 50 | + var installStateLocation = WorkloadInstallType.GetInstallStateFolder(new SdkFeatureBand("8.0.400"), Path.GetDirectoryName(_manifestRoot)!); |
| 51 | + var installStateFilePath = Path.Combine(installStateLocation, "default.json"); |
| 52 | + var installState = InstallStateContents.FromPath(installStateFilePath); |
| 53 | + installState.UseWorkloadSets = preferWorkloadSet; |
| 54 | + installState.Manifests = new Dictionary<string, string>() |
| 55 | + { |
| 56 | + { "ios", "11.0.6/8.0.400" } |
| 57 | + }; |
| 58 | + Directory.CreateDirectory(installStateLocation); |
| 59 | + File.WriteAllText(installStateFilePath, installState.ToString()); |
| 60 | + |
| 61 | + var sdkDirectoryWorkloadManifestProvider |
| 62 | + = new SdkDirectoryWorkloadManifestProvider(sdkRootPath: _fakeDotnetRootDirectory, sdkVersion: "8.0.400", userProfileDir: null, globalJsonPath: null); |
| 63 | + |
| 64 | + sdkDirectoryWorkloadManifestProvider.GetManifests().Single().ManifestVersion.Should().Be(preferWorkloadSet ? "11.0.2" : "11.0.6"); |
| 65 | + |
| 66 | + Directory.Delete(Path.Combine(_manifestRoot, "8.0.400"), recursive: true); |
| 67 | + } |
| 68 | + |
34 | 69 | [Theory]
|
35 | 70 | [InlineData(true)]
|
36 | 71 | [InlineData(false)]
|
@@ -418,6 +453,13 @@ public void WorkloadSetCanIncludeMultipleJsonFiles()
|
418 | 453 | CreateMockManifest(_manifestRoot, "8.0.200", "android", "33.0.2-rc.1", true);
|
419 | 454 | CreateMockManifest(_manifestRoot, "8.0.200", "android", "33.0.2", true);
|
420 | 455 |
|
| 456 | + // To prepare the resolver to work with workload sets, we need to specify 'workload sets' in the install state file. |
| 457 | + var installStateLocation = WorkloadInstallType.GetInstallStateFolder(new SdkFeatureBand("8.0.200"), Path.GetDirectoryName(_manifestRoot)!); |
| 458 | + var installStateFilePath = Path.Combine(installStateLocation, "default.json"); |
| 459 | + var installState = InstallStateContents.FromPath(installStateFilePath); |
| 460 | + installState.UseWorkloadSets = true; |
| 461 | + Directory.CreateDirectory(installStateLocation); |
| 462 | + File.WriteAllText(installStateFilePath, installState.ToString()); |
421 | 463 |
|
422 | 464 | var workloadSetDirectory = Path.Combine(_manifestRoot, "8.0.200", "workloadsets", "8.0.200");
|
423 | 465 | Directory.CreateDirectory(workloadSetDirectory);
|
@@ -1254,6 +1296,14 @@ private void CreateMockManifest(string manifestRoot, string featureBand, string
|
1254 | 1296 |
|
1255 | 1297 | private void CreateMockWorkloadSet(string manifestRoot, string featureBand, string workloadSetVersion, string workloadSetContents)
|
1256 | 1298 | {
|
| 1299 | + // To prepare the resolver to work with workload sets, we need to specify 'workload sets' in the install state file. |
| 1300 | + var installStateLocation = WorkloadInstallType.GetInstallStateFolder(new SdkFeatureBand(featureBand), Path.GetDirectoryName(manifestRoot)!); |
| 1301 | + var installStateFilePath = Path.Combine(installStateLocation, "default.json"); |
| 1302 | + var installState = InstallStateContents.FromPath(installStateFilePath); |
| 1303 | + installState.UseWorkloadSets = true; |
| 1304 | + Directory.CreateDirectory(installStateLocation); |
| 1305 | + File.WriteAllText(installStateFilePath, installState.ToString()); |
| 1306 | + |
1257 | 1307 | var workloadSetDirectory = Path.Combine(manifestRoot, featureBand, "workloadsets", workloadSetVersion);
|
1258 | 1308 | if (!Directory.Exists(workloadSetDirectory))
|
1259 | 1309 | {
|
|
0 commit comments