From ec6435b9e11f3658eec71cca3e30e4333e20f5d6 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Wed, 14 Jan 2015 18:22:49 +0100 Subject: [PATCH] Check if a project is already installed before add - references #550 --- src/Paket.Core/AddProcess.fs | 3 ++- src/Paket.Core/ProjectFile.fs | 8 ++++++++ src/Paket/Paket.fsproj | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Paket.Core/AddProcess.fs b/src/Paket.Core/AddProcess.fs index af2aa40809..aa3d180e50 100644 --- a/src/Paket.Core/AddProcess.fs +++ b/src/Paket.Core/AddProcess.fs @@ -17,7 +17,8 @@ let Add(dependenciesFileName, package, version, force, hard, interactive, instal if interactive then for project in ProjectFile.FindAllProjects(Path.GetDirectoryName lockFile.FileName) do - if Utils.askYesNo(sprintf " Install to %s?" project.Name) then + let notInstalled = project.HasPackageInstalled(NormalizedPackageName package) |> not + if notInstalled && Utils.askYesNo(sprintf " Install to %s?" project.Name) then ProjectFile.FindOrCreateReferencesFile(FileInfo(project.FileName)) .AddNuGetReference(package) .Save() diff --git a/src/Paket.Core/ProjectFile.fs b/src/Paket.Core/ProjectFile.fs index 560c6f78a6..f479c08084 100644 --- a/src/Paket.Core/ProjectFile.fs +++ b/src/Paket.Core/ProjectFile.fs @@ -77,6 +77,14 @@ type ProjectFile = member this.CreateNode(name) = this.Document.CreateElement(name, Constants.ProjectDefaultNameSpace) + member this.HasPackageInstalled(package:NormalizedPackageName) = + let proj = FileInfo(this.FileName) + match ProjectFile.FindReferencesFile proj with + | None -> false + | Some fileName -> + let lines = File.ReadAllLines(fileName) + lines |> Seq.exists (fun l -> l.ToLower() = package.ToString().ToLower()) + member this.CreateNode(name, text) = let node = this.CreateNode(name) node.InnerText <- text diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index 5195c21b7d..406873f8d0 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -28,12 +28,12 @@ update -f - restore + add nuget NUnit -i Project paket.exe - d:\code\jsonLD.Entities\src + d:\code\paketkopie pdbonly