2

I am trying to connect to Nuget Online repository using a HTTP URI. I am using PackageManager object and supplying it with DataServicePackageRepository object in the constructor. It does not seem to fetch the list. What I might be doing wrong ?

Should I use a different Repository class?

Here is my Package Manager initializer code

var remoteRepo = new NuGet.DataServicePackageRepository(new Uri("http://myserver/myrepo/nuget"));

PackageManager pkgMan = new PackageManager(remoteRepo, @"C:\Path\To\LocalRepoPath");
fahadash
  • 3,133
  • 1
  • 30
  • 59

1 Answers1

4

If you just want the list of packages you do not need to use the DataServicePackageRepository or the PackageManager directly. You can just use the PackageRepositoryFactory and the IPackageRepository.GetPackages() method.

The code below returns the top 10 packages ordered by the most downloaded. This is similar to what Visual Studio returns in the Manage Packages dialog.

string url = "https://www.nuget.org/api/v2/";
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository(url);
var packages = repo
    .GetPackages()
    .Where(p => p.IsLatestVersion)
    .OrderByDescending(p => p.DownloadCount)
    .Take(10);

foreach (IPackage package in packages) {
    Console.WriteLine(package);
}
Matt Ward
  • 47,057
  • 5
  • 93
  • 94