title: How can I list all local packages in the NuGet v3 API
body: <p>For context, I'm building an application that needs to download/unpack packages and their dependencies from arbitrary package sources (including the public gallery by default) and upgrade those packages to the latest version when requested. There are no project.json files or similar, it's all code driven. It's not a particularly complicated use case and didn't require too much code in the v2 APIs.</p>
  
  <p>In v3 however, I can't figure out how to correctly interact with the local package store. For example, the <code>FolderNuGetProject</code> class that I would have thought lists all the packages on disk at a given location in <code>FolderNuGetProject.GetInstalledPackagesAsync()</code> <a href="https://github.com/NuGet/NuGet.Client/blob/d74b04c1bdd3a6bb14b0ba6edd319e9c839c6eae/src/NuGet.Core/NuGet.ProjectManagement/Projects/FolderNuGetProject.cs#L50" rel="noreferrer">just returns an empty enumerable</a>. To make matters more confusing, <code>FolderNuGetProject.PackageExists()</code> actually does return whether the package exists on disk, which means <code>GetInstalledPackagesAsync()</code> and <code>PackageExists()</code> appear to be inconsistent.</p>
  
  <p>None of the other <code>NuGetProject</code> derivatives appear related to the file system. Is there some other way of listing the packages that have been installed into a particular folder? If I need to create my own <code>NuGetProject</code> (and I'm hoping I don't), are there any methods that will help with parsing NuGet-generated folder names into package IDs and versions, or is the only reliable way of getting the ID and version to open the nuspec (and are there any easy to find methods for that)?</p>
  
  <p>One interpretation of why this isn't working as I expect is that NuGetProject.GetInstalledPackagesAsync() isn't actually intended to get the installed packages (I.e., those that have been downloaded and unpacked), but rather those that have been declared in whatever project system is in use. For example, the <code>BuildIntegratedNuGetProject</code> class appears to return package references for the packages in the project.json, regardless of their status on disk. That would also explain why <code>FolderNuGetProject</code> just returns an empty enumerable, because there are no "declared" packages if you're just looking at the local repository.</p>
  
  <p>TL;DR: What is the best way to crawl the local package store and get the packages and versions that are present there?</p>
  
  <p>(this was also <a href="https://github.com/NuGet/Home/issues/2664" rel="noreferrer">issue #2664</a> on the NuGet GitHub project, but was moved here by request)</p>