From 6f94f31642e61c19f26498db9b321ce73d31dddd Mon Sep 17 00:00:00 2001 From: Jacques Eloff Date: Wed, 16 Jun 2021 12:49:14 -0700 Subject: [PATCH] Fix template, library pack generation (#7533) --- .../src/GenerateMsi.cs | 2 +- .../src/GenerateMsiBase.cs | 28 ++++++++++++++++--- .../src/GenerateWorkloadMsis.cs | 8 ++---- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsi.cs b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsi.cs index 8cbf2202242..0c34271f6fe 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsi.cs +++ b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsi.cs @@ -66,7 +66,7 @@ public override bool Execute() // For a single MSI we always generate all platforms and simply use the ID of the source package for // the SWIX projects. List msis = new(); - msis.AddRange(Generate(SourcePackage, null, OutputPath, GetInstallDir(kind), platforms)); + msis.AddRange(Generate(SourcePackage, null, OutputPath, kind, platforms)); Msis = msis.ToArray(); } catch (Exception e) diff --git a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs index 947f863a8ea..246e6d52b31 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs +++ b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs @@ -116,7 +116,7 @@ public string SuppressIces /// The NuGet package to convert into an MSI. /// The output path of the generated MSI. /// - protected IEnumerable Generate(string sourcePackage, string swixPackageId, string outputPath, string installDir, params string[] platforms) + protected IEnumerable Generate(string sourcePackage, string swixPackageId, string outputPath, WorkloadPackKind kind, params string[] platforms) { NugetPackage nupkg = new(sourcePackage, Log); List msis = new(); @@ -133,8 +133,28 @@ protected IEnumerable Generate(string sourcePackage, string swixPacka // Extract once, but harvest multiple times because some generated attributes are platform dependent. string packageContentsDirectory = Path.Combine(PackageDirectory, $"{nupkg.Identity}"); IEnumerable exclusions = GetExlusionPatterns(); - Log.LogMessage(MessageImportance.Low, $"Extracting '{sourcePackage}' to '{packageContentsDirectory}'"); - nupkg.Extract(packageContentsDirectory, exclusions); + string installDir = GetInstallDir(kind); + + if ((kind != WorkloadPackKind.Library) && (kind != WorkloadPackKind.Template)) + { + Log.LogMessage(MessageImportance.Low, $"Extracting '{sourcePackage}' to '{packageContentsDirectory}'"); + nupkg.Extract(packageContentsDirectory, exclusions); + } + else + { + // Library and template packs are not extracted. We want to harvest the nupkg itself, + // instead of the contents. The package is still copied to a separate folder for harvesting + // to avoid accidentally pulling in additional files and directories. + Log.LogMessage(MessageImportance.Low, $"Copying '{sourcePackage}' to '{packageContentsDirectory}'"); + + if (Directory.Exists(packageContentsDirectory)) + { + Directory.Delete(packageContentsDirectory, recursive: true); + } + Directory.CreateDirectory(packageContentsDirectory); + + File.Copy(sourcePackage, Path.Combine(packageContentsDirectory, Path.GetFileName(sourcePackage))); + } foreach (string platform in platforms) { @@ -407,7 +427,7 @@ internal static string GetInstallDir(WorkloadPackKind kind) { WorkloadPackKind.Framework or WorkloadPackKind.Sdk => "packs", WorkloadPackKind.Library => "library-packs", - WorkloadPackKind.Template => "templates", + WorkloadPackKind.Template => "template-packs", WorkloadPackKind.Tool => "tool-packs", _ => throw new ArgumentException($"Unknown package kind: {kind}"), }; diff --git a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateWorkloadMsis.cs b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateWorkloadMsis.cs index 43518c7c7d1..f55d7355f6a 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateWorkloadMsis.cs +++ b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateWorkloadMsis.cs @@ -89,7 +89,7 @@ public override bool Execute() // Always select the pack ID for the VS MSI package, even when aliased. msis.AddRange(Generate(sourcePackage, swixPackageId, - OutputPath, GetInstallDir(pack.Kind), platforms)); + OutputPath, pack.Kind, platforms)); } } @@ -111,12 +111,10 @@ private IEnumerable GetWorkloadPacks() IEnumerable manifests = WorkloadManifests.Select( w => WorkloadManifestReader.ReadWorkloadManifest(Path.GetFileNameWithoutExtension(w.ItemSpec), File.OpenRead(w.ItemSpec))); - // We want all workloads in all manifests iff - // 1. The workload isn't abstract - // 2. The workload has no platform or at least one platform includes Windows + // We want all workloads in all manifests iff the workload has no platform or at least one + // platform includes Windows var workloads = manifests.SelectMany(m => m.Workloads). Select(w => w.Value). - Where(wd => !wd.IsAbstract). Where(wd => (wd.Platforms == null) || wd.Platforms.Any(p => p.StartsWith("win"))); var packIds = workloads.SelectMany(w => w.Packs).Distinct();