anchor.diff:              use fileStream = File.Open (nuspecFile, FileMode.Create)
               doc.Save fileStream
   
  -    static member FixNuspecs (projectFile: ProjectFile, referencesFile: ReferencesFile, nuspecFileList:string list) =
  +    static member FixNuspecs (projectFile, ProjectFile, referencesFile:ReferencesFile, nuspecFileList:string list) =
  +        let attr (name: string) (node: XmlNode) =
  +            match node.Attributes.[name] with
  +            | null -> None
  +            | attr -> Some attr.InnerText
  +
  +        /// adjusts the given version requirement from a nuspec file using the 'locked' version of that same dependency
  +        let adjustRangeToLockedVersion (VersionRequirement(range, prerelease)) (lockedVersion: SemVerInfo) =
  +            let range' =
  +                match range with
  +                | VersionRange.Maximum max -> VersionRange.Between(VersionRangeBound.Including, lockedVersion, max, VersionRangeBound.Including)
  +                | VersionRange.GreaterThan _ -> VersionRange.GreaterThan lockedVersion
  +                | VersionRange.Minimum _ -> VersionRange.Minimum lockedVersion
  +                | VersionRange.Specific _ -> VersionRange.Specific lockedVersion
  +                | VersionRange.LessThan top -> VersionRange.Between(VersionRangeBound.Including, lockedVersion, top, VersionRangeBound.Excluding)
  +                | VersionRange.OverrideAll _ -> VersionRange.OverrideAll lockedVersion
  +                | VersionRange.Range(_, _, right, rightBound) -> VersionRange.Range(VersionRangeBound.Including, lockedVersion, right, rightBound)
  +
  +            VersionRequirement(range', prerelease)
           let deps = Dependencies.Locate(Path.GetDirectoryName(referencesFile.FileName))
           let locked = deps.GetLockFile()
           let projectReferences =
               projectFile.GetAllReferencedProjects(onlyWithOutput = true, cache = PackProcessCache.empty)
               |> List.map (fun proj -> proj.NameWithoutExtension)
               |> Set.ofList
  +        let depsFile = deps.GetDependenciesFile()
   
           // NuGet has thrown away "group" association, so this is best effort.
           let known =
  
positive.code:             if not (File.Exists nuspecFile) then
                  failwithf "Specified file '%s' does not exist." nuspecFile
  
          let directDeps =
              referencesFile.Groups
              |> Seq.collect (fun kv -> kv.Value.NugetPackages)
              |> Seq.map (fun i -> i.Name)
              |> Set.ofSeq
  
          for nuspecFile in nuspecFileList do
              let nuspecText = File.ReadAllText nuspecFile
  
negative.code:                 let nodesToRemove = ResizeArray()
                  for node in parent.ChildNodes do
                      if node.Name = "dependency" then
                          let packName = attr "id" node |> Option.map PackageName
                          let versionRange = attr "version" node |> Option.bind VersionRequirement.TryParse
  
                          // Ignore unknown packages, see https://github.com/fsprojects/Paket/issues/2694
                          // Assert that the version we remove it not newer than what we have in our resolution!
                          if known.Contains packName
                             && not (projectReferences.Contains packageName)
                             && not (directDeps.Contains (PackageName packageName)) then
                          match packName with
                          | Some IndirectDependency ->
                              nodesToRemove.Add node |> ignore
                          | Some UnknownDependency -> ()
                          | Some (DirectDependency ((GroupName(grp, _)) as g, (PackageName.PackageName(pkg, _) as p))) ->
                              match versionRange with
                              | Some versionRange ->
                                  match (g, p), versionRange with
                                  | MatchesRange -> ()
                                  | LockRangeNotFound ->
                                      printfn "Couldn't find a version range for package '%s' in group '%s', is this package in your paket.dependencies file?" pkg grp
                                      ()
                                  | NeedsRangeUpdate newVersionRange ->
                                      let nugetVersionRangeString = newVersionRange.FormatInNuGetSyntax()
                                      node.Attributes.["version"].InnerText <- nugetVersionRangeString
                              | None ->
                                  ()
                          | None ->
                              raise (Exception(sprintf "Could not read dependency id for package node %O" node))
  
                  if nodesToRemove.Count = 0 then
                      for node in parent.ChildNodes do traverse node
  