Skip to content

Commit

Permalink
Fix template, library pack generation (#7533)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeloff authored Jun 16, 2021
1 parent 6655bbb commit 6f94f31
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ITaskItem> 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)
Expand Down
28 changes: 24 additions & 4 deletions src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public string SuppressIces
/// <param name="sourcePackage">The NuGet package to convert into an MSI.</param>
/// <param name="outputPath">The output path of the generated MSI.</param>
/// <param name="platforms"></param>
protected IEnumerable<ITaskItem> Generate(string sourcePackage, string swixPackageId, string outputPath, string installDir, params string[] platforms)
protected IEnumerable<ITaskItem> Generate(string sourcePackage, string swixPackageId, string outputPath, WorkloadPackKind kind, params string[] platforms)
{
NugetPackage nupkg = new(sourcePackage, Log);
List<TaskItem> msis = new();
Expand All @@ -133,8 +133,28 @@ protected IEnumerable<ITaskItem> 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<string> 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)
{
Expand Down Expand Up @@ -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}"),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand All @@ -111,12 +111,10 @@ private IEnumerable<WorkloadPack> GetWorkloadPacks()
IEnumerable<WorkloadManifest> 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();
Expand Down

0 comments on commit 6f94f31

Please sign in to comment.