From c17de7fcb8e37291c7dff7e153cdabfdee4c5eb7 Mon Sep 17 00:00:00 2001 From: Jacques Eloff Date: Wed, 18 Aug 2021 13:41:45 -0700 Subject: [PATCH] Generate packs in parallel (#7764) --- .../src/GenerateMsiBase.cs | 4 ++-- .../src/GenerateWorkloadMsis.cs | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs index 3f36c9d0a11..c139e72dc51 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs +++ b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs @@ -157,7 +157,7 @@ protected IEnumerable Generate(string sourcePackage, string swixPacka File.Copy(sourcePackage, Path.Combine(packageContentsDirectory, Path.GetFileName(sourcePackage))); } - foreach (string platform in platforms) + System.Threading.Tasks.Parallel.ForEach(platforms, platform => { // Extract the MSI template and add it to the list of source files. List sourceFiles = new(); @@ -296,7 +296,7 @@ protected IEnumerable Generate(string sourcePackage, string swixPacka msi.SetMetadata(Metadata.PackageProject, GeneratePackageProject(msi.ItemSpec, msiJsonPath, platform, nupkg)); msis.Add(msi); - } + }); return msis; } diff --git a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateWorkloadMsis.cs b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateWorkloadMsis.cs index 6f34c971a29..50340821555 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateWorkloadMsis.cs +++ b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateWorkloadMsis.cs @@ -63,6 +63,8 @@ public override bool Execute() IEnumerable workloadPacks = GetWorkloadPacks(); List missingPackIds = new(workloadPacks.Select(p => $"{p.Id}")); + List<(string sourcePackage, string swixPackageId, string outputPath, WorkloadPackKind kind, string[] platforms)> packsToGenerate = new(); + foreach (WorkloadPack pack in workloadPacks) { Log.LogMessage($"Processing workload pack: {pack.Id}, Version: {pack.Version}"); @@ -88,11 +90,15 @@ public override bool Execute() string swixPackageId = $"{pack.Id.ToString().Replace(ShortNames)}.{pack.Version}"; // Always select the pack ID for the VS MSI package, even when aliased. - msis.AddRange(Generate(sourcePackage, swixPackageId, - OutputPath, pack.Kind, platforms)); + packsToGenerate.Add(new(sourcePackage, swixPackageId, OutputPath, pack.Kind, platforms)); } } + System.Threading.Tasks.Parallel.ForEach(packsToGenerate, p => + { + msis.AddRange(Generate(p.sourcePackage, p.swixPackageId, p.outputPath, p.kind, p.platforms)); + }); + Msis = msis.ToArray(); MissingPacks = missingPacks.ToArray(); }