diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 58d3f83f21..683c12df03 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +#### 0.22.12 - 14.01.2015 +* BUGFIX: `paket add` offered to add dependencies even when they are already added - https://github.com/fsprojects/Paket/issues/550 + #### 0.22.11 - 14.01.2015 * BUGFIX: Detect `Net20-client` - https://github.com/fsprojects/Paket/issues/547 diff --git a/src/Paket.Core/ProjectFile.fs b/src/Paket.Core/ProjectFile.fs index f479c08084..c1a7dfc608 100644 --- a/src/Paket.Core/ProjectFile.fs +++ b/src/Paket.Core/ProjectFile.fs @@ -82,8 +82,8 @@ type ProjectFile = match ProjectFile.FindReferencesFile proj with | None -> false | Some fileName -> - let lines = File.ReadAllLines(fileName) - lines |> Seq.exists (fun l -> l.ToLower() = package.ToString().ToLower()) + let referencesFile = ReferencesFile.FromFile fileName + referencesFile.NugetPackages |> Seq.exists (fun p -> NormalizedPackageName p = package) member this.CreateNode(name, text) = let node = this.CreateNode(name) diff --git a/src/Paket.Core/ReferencesFile.fs b/src/Paket.Core/ReferencesFile.fs index 86ef15c60a..2745d6d4fd 100644 --- a/src/Paket.Core/ReferencesFile.fs +++ b/src/Paket.Core/ReferencesFile.fs @@ -55,6 +55,15 @@ type ReferencesFile = tracefn "Adding %s to %s" referenceName (this.FileName) { this with NugetPackages = this.NugetPackages @ [packageName] } + member this.RemoveNuGetReference(packageName : PackageName) = + let (PackageName referenceName) = packageName + let normalized = NormalizedPackageName packageName + if this.NugetPackages |> Seq.exists (fun p -> NormalizedPackageName p = normalized) |> not then + this + else + tracefn "Removing %s from %s" referenceName (this.FileName) + { this with NugetPackages = this.NugetPackages |> List.filter (fun p -> NormalizedPackageName p <> normalized) } + member this.Save() = File.WriteAllText(this.FileName, this.ToString()) tracefn "References file saved to %s" this.FileName diff --git a/src/Paket.Core/RemoveProcess.fs b/src/Paket.Core/RemoveProcess.fs index 456f25ca01..3f610d1b6c 100644 --- a/src/Paket.Core/RemoveProcess.fs +++ b/src/Paket.Core/RemoveProcess.fs @@ -9,18 +9,13 @@ let Remove(dependenciesFileName, package:PackageName, force, hard, interactive, let (PackageName name) = package let root = Path.GetDirectoryName dependenciesFileName let allProjects = ProjectFile.FindAllProjects root - for project in allProjects do - let proj = FileInfo(project.FileName) - match ProjectFile.FindReferencesFile proj with - | None -> () - | Some fileName -> - let lines = File.ReadAllLines(fileName) - let installed = lines |> Seq.exists (fun l -> l.ToLower() = name.ToLower()) - if installed then - if (not interactive) || Utils.askYesNo(sprintf " Remove from %s?" project.Name) then - let newLines = lines |> Seq.filter (fun l -> l.ToLower() <> name.ToLower()) - File.WriteAllLines(fileName,newLines) - + for project in allProjects do + if project.HasPackageInstalled(NormalizedPackageName package) then + if (not interactive) || Utils.askYesNo(sprintf " Remove from %s?" project.Name) then + ProjectFile.FindOrCreateReferencesFile(FileInfo(project.FileName)) + .RemoveNuGetReference(package) + .Save() + // check we have it removed from all paket.references files let stillInstalled = allProjects diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index 406873f8d0..c5b722854e 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -28,7 +28,7 @@ update -f - add nuget NUnit -i + remove nuget nunit -i Project paket.exe