Skip to content

Large Solutions are restored in batches #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 41 additions & 14 deletions src/Paket.VisualStudio/Restore/PaketRestorer.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,61 @@
using System;
using System.Collections.Generic;
using Paket.VisualStudio.Utils;
using Paket.VisualStudio.SolutionExplorer;
using Paket.VisualStudio.Utils;

namespace Paket.VisualStudio.Restore
{
public class PaketRestorer : IPackageRestorer
{
private const int CommandLineLenght = 7000;

public void Restore(IEnumerable<RestoringProject> project)
{
string PaketSubCommand = "restore";
foreach (RestoringProject p in project)
PaketSubCommand += $" --references-file \"{p.ReferenceFile}\" ";

var limitSubCommand = LimitSubCommand(project, p => $" --references-file \"{p.ReferenceFile}\" ");
try
{
PaketLauncher.LaunchPaket(SolutionExplorerExtensions.GetPaketDirectory(), PaketSubCommand,
(send, args) => PaketOutputPane.OutputPane.OutputStringThreadSafe(args.Data + "\n"));
foreach (var s in limitSubCommand)
PaketLauncher.LaunchPaket(SolutionExplorerExtensions.GetPaketDirectory(), "restore" + s,
(send, args) => PaketOutputPane.OutputPane.OutputStringThreadSafe(args.Data + "\n"));
}
catch (PaketRuntimeException ex)
{
/* One of the known reasons for this block to get executed is that if the paket.exe is old then it is likely
* that --references-file is not supported and --references-files is supported instead. paket-4.8.4 for instance
*/
PaketOutputPane.OutputPane.OutputStringThreadSafe("Seems like you are using an older version of paket.exe. Trying restore with --references-files\n");
PaketSubCommand = "restore --references-files";
foreach (RestoringProject p in project)
PaketSubCommand += $" {p.ReferenceFile} ";
PaketLauncher.LaunchPaket(SolutionExplorerExtensions.GetPaketDirectory(), PaketSubCommand,
(send, args) => PaketOutputPane.OutputPane.OutputStringThreadSafe(args.Data + "\n"));
PaketOutputPane.OutputPane.OutputStringThreadSafe(
"Seems like you are using an older version of paket.exe. Trying restore with --references-files\n");

var limitedReferenceFiles = LimitSubCommand(project, p => $" {p.ReferenceFile} ");

foreach (var limitedReferenceFile in limitedReferenceFiles)
PaketLauncher.LaunchPaket(SolutionExplorerExtensions.GetPaketDirectory(),
"restore --references-files" + limitedReferenceFile,
(send, args) => PaketOutputPane.OutputPane.OutputStringThreadSafe(args.Data + "\n"));
}
}

private static List<string> LimitSubCommand(IEnumerable<RestoringProject> project,
Func<RestoringProject, string> commandResolver)
{
var subCommands = new List<string>();
var subCommand = string.Empty;
foreach (var p in project)
{
var commandToAdd = commandResolver(p);

if (subCommand.Length + commandToAdd.Length > CommandLineLenght)
{
subCommands.Add(subCommand);
subCommand = commandToAdd;
}
else
{
subCommand += commandToAdd;
}
}

return subCommands;
}
}
}
}