public IEnumerable <WorkloadId> GetInstalledWorkloads(SdkFeatureBand sdkFeatureBand) { SdkFeatureBand featureBand = new SdkFeatureBand(new ReleaseVersion(6, 0, 100)); if (sdkFeatureBand.Equals(featureBand)) { return(new[] { new WorkloadId("xamarin-android") }); } throw new Exception($"Should not pass other feature band {sdkFeatureBand}"); }
internal static void GetInstalledWorkloads(IWorkloadResolver workloadResolver, SdkFeatureBand sdkFeatureBand, InstalledWorkloadsCollection installedWorkloads) { IEnumerable <string> visualStudioWorkloadIds = GetAvailableVisualStudioWorkloads(workloadResolver); HashSet <string> installedWorkloadComponents = new(); // Visual Studio instances contain a large set of packages and we have to perform a linear // search to determine whether a matching SDK was installed and look for each installable // workload from the SDK. The search is optimized to only scan each set of packages once. foreach (ISetupInstance2 instance in GetVisualStudioInstances()) { ISetupPackageReference[] packages = instance.GetPackages(); bool hasMatchingSdk = false; installedWorkloadComponents.Clear(); for (int i = 0; i < packages.Length; i++) { string packageId = packages[i].GetId(); if (string.IsNullOrWhiteSpace(packageId)) { // Visual Studio already verifies the setup catalog at build time. If the package ID is empty // the catalog is likely corrupted. continue; } if (packageId.StartsWith(s_visualStudioSdkPackageIdPrefix)) { // After trimming the package prefix we should be left with a valid semantic version. If we can't // parse the version we'll skip this instance. if (!ReleaseVersion.TryParse(packageId.Substring(s_visualStudioSdkPackageIdPrefix.Length), out ReleaseVersion visualStudioSdkVersion)) { break; } SdkFeatureBand visualStudioSdkFeatureBand = new SdkFeatureBand(visualStudioSdkVersion); // The feature band of the SDK in VS must match that of the SDK on which we're running. if (!visualStudioSdkFeatureBand.Equals(sdkFeatureBand)) { break; } hasMatchingSdk = true; continue; } if (visualStudioWorkloadIds.Contains(packageId, StringComparer.OrdinalIgnoreCase)) { // Normalize back to an SDK style workload ID. installedWorkloadComponents.Add(packageId.Replace('.', '-')); } } if (hasMatchingSdk) { foreach (string id in installedWorkloadComponents) { installedWorkloads.Add(id, $"VS {instance.GetInstallationVersion()}"); } } } }