Skip to content

Commit

Permalink
C#: Do not run multiple dotnet/nuget restore in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Apr 17, 2024
1 parent da3fa22 commit 5ef611a
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void RestoreProjects(IEnumerable<string> projects, out IEnumerable<strin
var nugetSourceFailures = 0;
var assetFiles = new List<string>();
var sync = new object();
Parallel.ForEach(projects, new ParallelOptions { MaxDegreeOfParallelism = DependencyManager.Threads }, project =>
foreach (var project in projects)
{
logger.LogInfo($"Restoring project {project}...");
var res = dotnet.Restore(new(project, PackageDirectory.DirInfo.FullName, ForceDotnetRefAssemblyFetching: true));
Expand All @@ -224,7 +224,7 @@ private void RestoreProjects(IEnumerable<string> projects, out IEnumerable<strin
}
assetFiles.AddRange(res.AssetsFilePaths);
}
});
}
assets = assetFiles;
compilationInfoContainer.CompilationInfos.Add(("Successfully restored project files", successCount.ToString()));
compilationInfoContainer.CompilationInfos.Add(("Failed project restore with package source error", nugetSourceFailures.ToString()));
Expand Down Expand Up @@ -285,19 +285,19 @@ private void RestoreProjects(IEnumerable<string> projects, out IEnumerable<strin
var successCount = 0;
var sync = new object();

Parallel.ForEach(notYetDownloadedPackages, new ParallelOptions { MaxDegreeOfParallelism = DependencyManager.Threads }, package =>
foreach (var package in notYetDownloadedPackages)
{
var success = TryRestorePackageManually(package.Name, nugetConfig, package.PackageReferenceSource, tryWithoutNugetConfig: fallbackNugetFeeds is null);
if (!success)
{
return;
continue;
}

lock (sync)
{
successCount++;
}
});
}

compilationInfoContainer.CompilationInfos.Add(("Successfully ran fallback nuget restore", successCount.ToString()));

Expand Down

0 comments on commit 5ef611a

Please sign in to comment.