From 5541d3be9cc883ee4d166eecc231e4037f662dd9 Mon Sep 17 00:00:00 2001 From: Ruh Ullah Shah Date: Thu, 19 Oct 2017 12:06:14 +0200 Subject: [PATCH] Fix project restore compatibility issue with older versions of Paket --- .../Restore/PaketRestorer.cs | 19 +++++++++++++++++-- src/Paket.VisualStudio/Utils/PaketLauncher.cs | 3 ++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Paket.VisualStudio/Restore/PaketRestorer.cs b/src/Paket.VisualStudio/Restore/PaketRestorer.cs index 8be839746..d1168b3de 100644 --- a/src/Paket.VisualStudio/Restore/PaketRestorer.cs +++ b/src/Paket.VisualStudio/Restore/PaketRestorer.cs @@ -12,8 +12,23 @@ public void Restore(IEnumerable project) foreach (RestoringProject p in project) PaketSubCommand += $" --references-file {p.ReferenceFile} "; - PaketLauncher.LaunchPaket(SolutionExplorerExtensions.GetPaketDirectory(), PaketSubCommand, - (send, args) => PaketOutputPane.OutputPane.OutputStringThreadSafe(args.Data + "\n")); + try + { + PaketLauncher.LaunchPaket(SolutionExplorerExtensions.GetPaketDirectory(), PaketSubCommand, + (send, args) => PaketOutputPane.OutputPane.OutputStringThreadSafe(args.Data + "\n")); + } + catch (System.Exception 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")); + } } } } \ No newline at end of file diff --git a/src/Paket.VisualStudio/Utils/PaketLauncher.cs b/src/Paket.VisualStudio/Utils/PaketLauncher.cs index c73682718..19892ab90 100644 --- a/src/Paket.VisualStudio/Utils/PaketLauncher.cs +++ b/src/Paket.VisualStudio/Utils/PaketLauncher.cs @@ -53,7 +53,8 @@ public static void LaunchPaket(string SolutionDirectory, string PaketSubCommand, /* At this point, all is well .paket\paket.exe exists or .paket\paket.bootstrapper.exe downloaded it successfully. * Now issue the original command to .paket\paket.exe */ - LaunchProcess(SolutionDirectory, PAKET_EXE, PaketSubCommand, PaketDataReceivedHandler); + if (LaunchProcess(SolutionDirectory, PAKET_EXE, PaketSubCommand, PaketDataReceivedHandler) != 0) + throw new System.Exception($"{PAKET_EXE} {PaketSubCommand} failed"); } } } \ No newline at end of file