public void ItCanOverrideDefaultValues() { WorkloadManifest manifest = Create("WorkloadManifest.json"); WorkloadDefinition definition = manifest.Workloads.FirstOrDefault().Value; ITaskItem[] resources = new ITaskItem[] { new TaskItem("microsoft-net-sdk-blazorwebassembly-aot", new Dictionary <string, string> { { "Title", "AOT" }, { "Description", "A long wordy description." }, { "Category", "Compilers, build tools, and runtimes" } }) }; VisualStudioComponent component = VisualStudioComponent.Create(null, manifest, definition, "1.2.3.4", NoItems, resources, NoItems); string swixProjDirectory = RandomPath; Directory.CreateDirectory(swixProjDirectory); component.Generate(swixProjDirectory); string componentResSwr = File.ReadAllText(Path.Combine(swixProjDirectory, "component.res.swr")); Assert.Contains(@"title=""AOT""", componentResSwr); Assert.Contains(@"description=""A long wordy description.""", componentResSwr); Assert.Contains(@"category=""Compilers, build tools, and runtimes""", componentResSwr); }
public WorkloadPackGroup(WorkloadDefinition workload, string workloadManifestVersion, List <WorkloadResolver.PackInfo> packs, List <WorkloadPackId> unavailablePacks) { Workload = workload; WorkloadManifestVersion = workloadManifestVersion; Packs = packs; UnavailablePacks = unavailablePacks; }
/// <summary> /// Creates a <see cref="VisualStudioComponent"/> using a workload definition. /// </summary> /// <param name="Definition"></param> /// <param name="packs"></param> /// <returns></returns> public static VisualStudioComponent Create(WorkloadManifest manifest, WorkloadDefinition definition) { VisualStudioComponent package = new(Utils.ToSafeId(definition.Id.ToString()), definition.Description, definition.Description, new Version($"{manifest.Version}.0")); foreach (WorkloadPackId packId in definition.Packs) { package.AddDependency(manifest.Packs[packId]); } return(package); }
public void ItCreatesSafeComponentIds() { WorkloadManifest manifest = Create("WorkloadManifest.json"); WorkloadDefinition definition = manifest.Workloads.FirstOrDefault().Value; VisualStudioComponent component = VisualStudioComponent.Create(null, manifest, definition, "1.2.3.4", NoItems, NoItems, NoItems); string swixProjDirectory = RandomPath; Directory.CreateDirectory(swixProjDirectory); component.Generate(swixProjDirectory); string componentSwr = File.ReadAllText(Path.Combine(swixProjDirectory, "component.swr")); Assert.Contains(@"microsoft.net.sdk.blazorwebassembly.aot", componentSwr); }
public void ItCreatesComponentsWhenWorkloadsDoNotIncludePacks() { WorkloadManifest manifest = Create("mauiWorkloadManifest.json"); WorkloadDefinition definition = (WorkloadDefinition)manifest.Workloads.FirstOrDefault().Value; VisualStudioComponent component = VisualStudioComponent.Create(null, manifest, definition, NoItems, NoItems, NoItems, NoItems); string swixProjDirectory = RandomPath; Directory.CreateDirectory(swixProjDirectory); component.Generate(swixProjDirectory); string componentSwr = File.ReadAllText(Path.Combine(swixProjDirectory, "component.swr")); Assert.Contains(@"vs.dependency id=maui.mobile", componentSwr); Assert.Contains(@"vs.dependency id=maui.desktop", componentSwr); }
public void ItAssignsDefaultValues() { WorkloadManifest manifest = Create("WorkloadManifest.json"); WorkloadDefinition definition = manifest.Workloads.FirstOrDefault().Value; VisualStudioComponent component = VisualStudioComponent.Create(null, manifest, definition, "1.2.3.4", NoItems, NoItems, NoItems); string swixProjDirectory = RandomPath; Directory.CreateDirectory(swixProjDirectory); component.Generate(swixProjDirectory); string componentResSwr = File.ReadAllText(Path.Combine(swixProjDirectory, "component.res.swr")); Assert.Contains(@"title=""Blazor WebAssembly AOT workload""", componentResSwr); Assert.Contains(@"description=""Blazor WebAssembly AOT workload""", componentResSwr); Assert.Contains(@"category="".NET""", componentResSwr); }
/// <summary> /// Creates a <see cref="VisualStudioComponent"/> using a workload definition. /// </summary> /// <param name="manifest"></param> /// <param name="workload"></param> /// <param name="componentVersions"></param> /// <param name="shortNames"></param> /// <param name="shortNameMetadata"></param> /// <param name="componentResources"></param> /// <returns></returns> public static VisualStudioComponent Create(TaskLoggingHelper log, WorkloadManifest manifest, WorkloadDefinition workload, ITaskItem[] componentVersions, ITaskItem[] shortNames, ITaskItem[] componentResources, ITaskItem[] missingPacks) { log?.LogMessage("Creating Visual Studio component"); string workloadId = $"{workload.Id}"; // If there's an explicit version mapping we use that, otherwise we fall back to the manifest version // and normalize it since it can have semantic information and Visual Studio components do not support that. ITaskItem versionItem = componentVersions?.Where(v => string.Equals(v.ItemSpec, workloadId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); Version version = (versionItem != null) && !string.IsNullOrWhiteSpace(versionItem.GetMetadata(Metadata.Version)) ? new Version(versionItem.GetMetadata(Metadata.Version)) : (new NuGetVersion(manifest.Version)).Version; ITaskItem resourceItem = componentResources?.Where( r => string.Equals(r.ItemSpec, workloadId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); // Workload definitions do not have separate title/description fields so the only option // is to default to the workload description for both. string title = resourceItem?.GetMetadata(Metadata.Title) ?? workload.Description; string description = resourceItem?.GetMetadata(Metadata.Description) ?? workload.Description; string category = resourceItem?.GetMetadata(Metadata.Category) ?? ".NET"; string isUiGroup = workload.IsAbstract ? "yes" : "no"; VisualStudioComponent component = new(Utils.ToSafeId(workloadId), description, title, version, isUiGroup, shortNames, category); IEnumerable <string> missingPackIds = missingPacks.Select(p => p.ItemSpec); log?.LogMessage(MessageImportance.Low, $"Missing packs: {string.Join(", ", missingPackIds)}"); // If the workload extends other workloads, we add those as component dependencies before // processing direct pack dependencies if (workload.Extends?.Count() > 0) { foreach (WorkloadDefinitionId dependency in workload.Extends) { // Component dependencies, aka. workload extensions only have minimum version dependencies. component.AddDependency($"{Utils.ToSafeId(dependency.ToString())}", new Version("1.0.0.0"), maxVersion: null); } } if (workload.Packs != null) { // Visual Studio is case-insensitive. IEnumerable <WorkloadPackId> packIds = workload.Packs.Where(p => !missingPackIds.Contains($"{p}", StringComparer.OrdinalIgnoreCase)); log?.LogMessage(MessageImportance.Low, $"Packs: {string.Join(", ", packIds.Select(p => $"{p}"))}"); foreach (WorkloadPackId packId in packIds) { // Check whether the pack dependency is aliased to non-Windows RIDs. If so, we can't add a dependency for the pack // because we won't be able to create installers. if (manifest.Packs.TryGetValue(packId, out WorkloadPack pack)) { if (pack.IsAlias && !pack.AliasTo.Keys.Any(rid => s_SupportedRids.Contains(rid))) { log?.LogMessage($"Workload {workload.Id} supports Windows, but none of its aliased packs do. Only the following pack aliases were found: {String.Join("", "", pack.AliasTo.Keys)}."); continue; } else { log?.LogMessage(MessageImportance.Low, $"Adding component dependency for {packId} "); component.AddDependency(manifest.Packs[packId]); } } //if (manifest.Packs.ContainsKey(packId)) //{ // component.AddDependency(manifest.Packs[packId]); //} //else //{ // log?.LogMessage(MessageImportance.High, $"Missing Visual Studio component dependency, packId: {packId}."); //} } } return(component); }
/// <summary> /// Creates a <see cref="VisualStudioComponent"/> using a workload definition. /// </summary> /// <param name="manifest"></param> /// <param name="workload"></param> /// <param name="componentVersions"></param> /// <param name="shortNames"></param> /// <param name="shortNameMetadata"></param> /// <param name="componentResources"></param> /// <returns></returns> public static VisualStudioComponent Create(TaskLoggingHelper log, WorkloadManifest manifest, WorkloadDefinition workload, ITaskItem[] componentVersions, ITaskItem[] shortNames, ITaskItem[] componentResources, ITaskItem[] missingPacks) { log?.LogMessage("Creating Visual Studio component"); string workloadId = $"{workload.Id}"; // If there's an explicit version mapping we use that, otherwise we fall back to the manifest version // and normalize it since it can have semantic information and Visual Studio components do not support that. ITaskItem versionItem = componentVersions?.Where(v => string.Equals(v.ItemSpec, workloadId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); Version version = (versionItem != null) && !string.IsNullOrWhiteSpace(versionItem.GetMetadata(Metadata.Version)) ? new Version(versionItem.GetMetadata(Metadata.Version)) : (new NuGetVersion(manifest.Version)).Version; ITaskItem resourceItem = componentResources?.Where( r => string.Equals(r.ItemSpec, workloadId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); // Workload definitions do not have separate title/description fields so the only option // is to default to the workload description for both. string title = resourceItem?.GetMetadata(Metadata.Title) ?? workload.Description; string description = resourceItem?.GetMetadata(Metadata.Description) ?? workload.Description; string category = resourceItem?.GetMetadata(Metadata.Category) ?? ".NET"; VisualStudioComponent component = new(Utils.ToSafeId(workloadId), description, title, version, shortNames, category); IEnumerable <string> missingPackIds = missingPacks.Select(p => p.ItemSpec); log?.LogMessage(MessageImportance.Low, $"Missing packs: {string.Join(", ", missingPackIds)}"); // Visual Studio is case-insensitive. IEnumerable <WorkloadPackId> packIds = workload.Packs.Where(p => !missingPackIds.Contains($"{p}", StringComparer.OrdinalIgnoreCase)); log?.LogMessage(MessageImportance.Low, $"Packs: {string.Join(", ", packIds.Select(p=>$"{p}"))}"); foreach (WorkloadPackId packId in packIds) { log?.LogMessage(MessageImportance.Low, $"Adding component dependency for {packId} "); component.AddDependency(manifest.Packs[packId]); } return(component); }
/// <summary> /// Creates a <see cref="VisualStudioComponent"/> using a workload definition. /// </summary> /// <param name="manifest"></param> /// <param name="workload"></param> /// <param name="componentVersion"></param> /// <param name="shortNames"></param> /// <param name="shortNameMetadata"></param> /// <param name="componentResources"></param> /// <returns></returns> public static VisualStudioComponent Create(TaskLoggingHelper log, WorkloadManifest manifest, WorkloadDefinition workload, string componentVersion, ITaskItem[] shortNames, ITaskItem[] componentResources, ITaskItem[] missingPacks) { log?.LogMessage("Creating Visual Studio component"); Version version = string.IsNullOrWhiteSpace(componentVersion) ? new Version($"{manifest.Version}.0") : new Version(componentVersion); ITaskItem resourceItem = componentResources?.Where( r => string.Equals(r.ItemSpec, workload.Id.ToString(), StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); // Workload definitions do not have separate title/description fields so the only option // is to default to the workload description for both. string title = resourceItem?.GetMetadata(Metadata.Title) ?? workload.Description; string description = resourceItem?.GetMetadata(Metadata.Description) ?? workload.Description; string category = resourceItem?.GetMetadata(Metadata.Category) ?? ".NET"; VisualStudioComponent component = new(Utils.ToSafeId(workload.Id.ToString()), description, title, version, shortNames, category); IEnumerable <string> missingPackIds = missingPacks.Select(p => p.ItemSpec); log?.LogMessage(MessageImportance.Low, $"Missing packs: {string.Join(", ", missingPackIds)}"); // Visual Studio is case-insensitive. IEnumerable <WorkloadPackId> packIds = workload.Packs.Where(p => !missingPackIds.Contains($"{p}", StringComparer.OrdinalIgnoreCase)); log?.LogMessage(MessageImportance.Low, $"Packs: {string.Join(", ", packIds.Select(p=>$"{p}"))}"); foreach (WorkloadPackId packId in packIds) { log?.LogMessage(MessageImportance.Low, $"Adding component dependency for {packId} "); component.AddDependency(manifest.Packs[packId]); } return(component); }