Extend the NuGet package programmatically using NuGet.Core

Currently, I am packing several files and clicking them on the NuGet channel on one of our servers using the command line tool. Instead of using the command line tool, I set up the project using Nuget.Core and was able to successfully create the package. Now I am trying to pull this package from my machine to the NuGet channel through NuGet.Core. Using a command line tool that looks like this (and I did it too):

nuget.exe push package.nupkg -ApiKey MYAPIKEY -Source http://nugetpackagefeedaddress 

I want to replicate the push function using NuGet.Core. So far, I have managed to get two repositories from PackageRepositoryFactory so far, one for the local machine path and one for the package feed, and then extract the package from the local one and try and add it to the feed, like this:

 var remoteRepo = PackageRepositoryFactory.Default.CreateRepository("myNugetPackagefeedUrl"); var localRepo = PackageRepositoryFactory.Default.CreateRepository(@"locationOfLocalPackage"); var package = localRepo.FindPackagesById("packageId").First(); remoteRepo.AddPackage(package); 

This code causes a NotSupportedException indicate that "The specified method is not supported"

Can I push packages using NuGet.Core? and am I somewhere next to it with the above code?

Note. I know that I can wrap the nuget.exe call and call it from .NET, but I would like to either package, or click from NuGet.Core, or do this by wrapping the calls in nuget.exe than half and half

+8
c # nuget nuget-package
source share
2 answers

So it turns out I was looking in the wrong place. The method I wanted was PushPackage on a PackageServer

Now the code is as follows:

 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 userAgent when upgrading PackageServer will be. Similarly, if someone has any recommendations regarding what is needed to time out or disable buffering options, let me know (for example, this is a timeout in seconds, seconds, etc.).

The signature of the PushPackage method is as follows:

 void PackageServer.PushPackage(string apiKey, IPackage package, long packageSize, int timeout, bool disableBuffering) 
+9
source share

In addition to rh072005, answer:

  • Waiting time is milliseconds, be careful.
  • Uri is difficult. To implement NuGet.Server PushPackage uri must be " http: // nugetserveraddress , while for IPackageRepository Uri objects it becomes" http: // nugetserveraddress / nuget "
  • For large packets, you will receive (404) not found if the IIS server is not configured to accept large requests.
+1
source share

All Articles