Use NuGet package cache instead of the API if possible
end
end
+
+--
+-- Given a package string, returns a table containing "verbatimVersion",
+-- "version" and for C# packages, "packageEntries".
+--
+
function nuget2010.packageAPIInfo(prj, package)
local id = nuget2010.packageId(package)
local version = nuget2010.packageVersion(package)
+ -- It's possible that NuGet already has this package in its cache. In
+ -- that case we can examine the nuspec file and the file listing
+ -- locally.
+
+ local function examinePackageFromCache()
+ -- It should be possible to implement this for platforms other than
+ -- Windows, but we'll need to figure out where the NuGet cache is on
+ -- these platforms (or if they even have one).
+
+ if not os.ishost("windows") then
+ return
+ end
+
+ local cachePath = path.translate(path.join(os.getenv("userprofile"), ".nuget/packages", id))
+
+ if os.isdir(cachePath) then
+ local packageAPIInfo = {}
+
+ printf("Examining cached NuGet package '%s'...", id)
+ io.flush()
+
+ local versionPath = path.translate(path.join(cachePath, version))
+
+ local nuspecPath = path.translate(path.join(versionPath, id .. ".nuspec"))
+
+ if not os.isfile(nuspecPath) then
+ return
+ end
+
+ local nuspec = io.readfile(nuspecPath)
+
+ if not nuspec then
+ return
+ end
+
+ packageAPIInfo.verbatimVersion = nuspec:match("<version>(.+)</version>")
+ packageAPIInfo.version = version
+
+ if not packageAPIInfo.verbatimVersion then
+ return
+ end
+
+ if p.project.isdotnet(prj) then
+ -- Using the local file listing for "packageEntries" might
+ -- not exactly match what we would get from the API but this
+ -- doesn't matter. At the moment of writing, we're only
+ -- interested in knowing what DLL files the package
+ -- contains.
+
+ packageAPIInfo.packageEntries = {}
+
+ for _, file in ipairs(os.matchfiles(path.translate(path.join(versionPath, "**")))) do
+ local extension = path.getextension(file)
+
+ if extension ~= ".nupkg" and extension ~= ".sha512" then
+ table.insert(packageAPIInfo.packageEntries, path.translate(path.getrelative(versionPath, file)))
+ end
+ end
+
+ if #packageAPIInfo.packageEntries == 0 then
+ return
+ end
+
+ if nuspec:match("<frameworkAssemblies>(.+)</frameworkAssemblies>") then
+ p.warn("NuGet package '%s' may depend on .NET Framework assemblies - package dependencies are currently unimplemented", id)
+ end
+ end
+
+ if nuspec:match("<dependencies>(.+)</dependencies>") then
+ p.warn("NuGet package '%s' may depend on other packages - package dependencies are currently unimplemented", id)
+ end
+
+ packageAPIInfos[package] = packageAPIInfo
+ end
+ end
+
+ if not packageAPIInfos[package] then
+ examinePackageFromCache()
+ end
+
+ -- If we didn't find the package from the cache, use the NuGet API
+ -- instead.
+
+ if not packageAPIInfos[package] then
if not packageSourceInfos[prj.nugetsource] then
local packageSourceInfo = {}
packageSourceInfos[prj.nugetsource] = packageSourceInfo
end
- if not packageAPIInfos[package] then
local packageAPIInfo = {}
printf("Examining NuGet package '%s'...", id)
