@@ -7,6 +7,7 @@ open System.Net
77open System.Xml
88open Newtonsoft.Json
99open Ionic.Zip
10+ open System.Xml .Linq
1011
1112/// Gets versions of the given package.
1213let getAllVersions ( nugetURL , package ) =
@@ -61,6 +62,30 @@ let getDependencies nugetURL package version =
6162 |> Array.toList
6263 return packages
6364 }
65+
66+ /// Gets hash value and algorithm from Nuget.
67+ let getDetailsFromNuget name version =
68+ async {
69+ use wc = new WebClient()
70+ let! data = sprintf " https://www.nuget.org/api/v2/Packages(Id='%s ',Version='%s ')" name version
71+ |> wc.DownloadStringTaskAsync
72+ |> Async.AwaitTask
73+ let data = XDocument.Parse data
74+
75+ let getAttribute =
76+ let rootNs = XName.Get( " entry" , " http://www.w3.org/2005/Atom" )
77+ let propertiesNs =
78+ XName.Get( " properties" , " http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" )
79+ let attributesNs attribute =
80+ XName.Get( attribute, " http://schemas.microsoft.com/ado/2007/08/dataservices" )
81+
82+ let properties =
83+ rootNs
84+ |> data.Element
85+ |> fun entry -> entry.Element( propertiesNs)
86+ fun attribute -> properties.Element( attributesNs attribute). Value
87+ return ( getAttribute " PackageHash" , getAttribute " PackageHashAlgorithm" )
88+ }
6489
6590/// The NuGet cache folder.
6691let CacheFolder =
@@ -89,7 +114,7 @@ let DownloadPackage(source, name, version, force) =
89114 do ! client.DownloadFileTaskAsync( Uri url, targetFileName)
90115 |> Async.AwaitIAsyncResult
91116 |> Async.Ignore
92- let! hashDetails = Hashing. getDetailsFromNuget name version
117+ let! hashDetails = getDetailsFromNuget name version
93118 match hashDetails |> Hashing.compareWith name targetFile with
94119 | Some error ->
95120 // TODO: File.Delete targetFileName
0 commit comments