Using the nuget.core library in C# to download all packages from a nuget repository is difficult. The class PackageDownloader is not handy. I ended up using the WebClient to download the package.
This is the code:
string nugetBase = "http://proget.company.com/nuget/company-repo";
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository(nugetBase);
var query = repo.Search("", true);
string path = "c:\\packages";
WebClient cln = new WebClient();
foreach (DataServicePackage elem in query)
{
string dir = path + "\\" + elem.Id;
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
cln.DownloadFile(elem.DownloadUrl.AbsoluteUri, (path + "\\" + elem.Id + "\\" + elem.Id + "." + elem.Version + ".nupkg"));
}
Geen opmerkingen:
Een reactie posten