Is it possible to push a Nuget Package using Invoke-WebRequest?

Hi Everyone!

The title pretty much sums it up. I have a customer that’s asking this question, and I can’t seem to reach to the conclusion if its possible or not.

So far I have the code below, but I still don’t know how to actually reference the package to send it over:

$OctopusServerUrl = $env:OctopusURL
$OctopusApiKey = $env:OctopusAPIKey
$header = @{ "X-Octopus-ApiKey" = $OctopusApiKey }

Invoke-WebRequest -Uri $OctopusServerUrl/nuget/packages -Headers $header -Method Put -ContentType 'multipart/form-data; boundary'

I’m trying to push the package to Octopus Deploy’s built in package repository, but any code snippet to push to a different Package repository should help me get on track.


In theory, yes. It’s probably going to be a PITA, though. I don’t know what NuGet expects in terms of data, but I’m guessing its a multipart form, with Base64-encoded binary for the actual package. None of which is exceptionally easy to do manually. But there are a bunch of commands out there for using NuGet from PowerShell; would those not be useful in your situation?

Hey Don,

This was actually for a customer that insisted on using Invoke-WebRequest for this. I kinda figured it was going to be a PITA.

I’m waiting for his reply, but if he still wants to do this via Powershell (he’s claiming that nuget.exe wasn’t fast enough), I’ll point him to these commands you are mentioning.

Thanks for the reply :slight_smile: