diff --git a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs index c139e72dc51..11b7560fa4b 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs +++ b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/GenerateMsiBase.cs @@ -110,6 +110,11 @@ public string SuppressIces set; } + /// + /// Used to synchronize access to the NuGet being extracted. + /// + private readonly object extractNuGetLock = new object(); + /// /// Generate a set of MSIs for the specified platforms using the specified NuGet package. /// @@ -118,7 +123,11 @@ public string SuppressIces /// protected IEnumerable Generate(string sourcePackage, string swixPackageId, string outputPath, WorkloadPackKind kind, params string[] platforms) { - NugetPackage nupkg = new(sourcePackage, Log); + NugetPackage nupkg = null; + lock (extractNuGetLock) + { + nupkg = new(sourcePackage, Log); + } List msis = new(); // MSI ProductName defaults to the package title and fallback to the package ID with a warning. @@ -139,7 +148,10 @@ protected IEnumerable Generate(string sourcePackage, string swixPacka if ((kind != WorkloadPackKind.Library) && (kind != WorkloadPackKind.Template)) { Log.LogMessage(MessageImportance.Low, $"Extracting '{sourcePackage}' to '{packageContentsDirectory}'"); - nupkg.Extract(packageContentsDirectory, exclusions); + lock (extractNuGetLock) + { + nupkg.Extract(packageContentsDirectory, exclusions); + } } else { @@ -188,9 +200,12 @@ protected IEnumerable Generate(string sourcePackage, string swixPacka SourceDirectory = packageContentsDirectory }; - if (!heat.Execute()) + lock (extractNuGetLock) { - throw new Exception($"Failed to harvest package contents."); + if (!heat.Execute()) + { + throw new Exception($"Failed to harvest package contents."); + } } // Compile the MSI sources