Push NuGet package programmatically using NuGet.Core
So it turns out I was looking in the wrong place entirely. The method I wanted was PushPackage
on PackageServer
The code now looks like this
var localRepo = PackageRepositoryFactory.Default.CreateRepository(@"locationOfLocalPackage");
var package = localRepo.FindPackagesById("packageId").First();
var packageFile = new FileInfo(@"packagePath");
var size = packageFile .Length;
var ps = new PackageServer("http://nugetpackagefeedaddress", "userAgent");
ps.PushPackage("MYAPIKEY", package, size, 1800, false);
I'm not sure what the best values for the userAgent parameter when newing up the PackageServer
would be. Similarly if anyone has any advice on what the timeout or disableBuffering parameters want to be, let me know (for example is the timeout in ms, seconds etc.)
The PushPackage method signature looks like this:
void PackageServer.PushPackage(string apiKey, IPackage package, long packageSize, int timeout, bool disableBuffering)
In addition to rh072005's answer:
- Timeout is in milliseconds, be careful.
- Uri is tricky. For NuGet.Server implementation PushPackage uri should be "http://nugetserveraddress" while for IPackageRepository objects Uri becomes "http://nugetserveraddress/nuget"
- For large packages you will get (404) Not Found if IIS server is not configured to accept large requests.