Solution
Credit to mklement0
Here's what I ended up doing to publish my bin\MyModule.0.1.0.nupkg
module to PSGallery:
- Rename
bin\MyModule.0.1.0.nupkg
tobin\MyModule.0.1.0.zip
- Extract
bin\MyModule.0.1.0.zip
tobin\MyModule\
(the name of the extracted folder had to match the name of the.psd1
file inside, so in my case there was now abin\MyModule\MyModule.psd1
file). - Delete the
[Content_Types].xml
file from inside the extracted folder (not deleting this causes an error when you try to download and install the module from PSGallery, seemingly caused by 2 copies of that file being present in the resulting.nupkg
).
Then I was able to run this command:
PS> Publish-Module -NuGetApiKey xxx -Path .\bin\MyModule
And it worked! My module is now published to PSGallery.
Original Post
I have a Powershell module generated and packaged as a .nupkg file by Autorest.Powershell. I now want to publish my module to the Powershell Gallery, but can't figure out how to get it to work. I have tried:
PS> Publish-Module -NuGetApiKey xxx -Path .\bin\MyModule.0.1.0.nupkg
Publish-Module: The specified path '.\bin\MyModule.0.1.0.nupkg' is not a valid directory.
PS> Publish-Module -NuGetApiKey xxx -Path .\bin\
Publish-Module: The specified module with path '.\bin' was not published because no valid module was found with that path.
PS> Publish-Module -NuGetApiKey xxx -Name .\bin\MyModule.0.1.0.nupkg
Get-Module: C:\Users\bport\Documents\PowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:10630
Line |
10630 | … $module = Microsoft.PowerShell.Core\Get-Module -ListAvailable -Name …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The specified module 'D:\workarea\bin\MyModule.0.1.0.nupkg'
| was not found. Update the Name parameter to point to a valid path, and then try again.
Publish-Module: The specified module '.\bin\MyModule.0.1.0.nupkg' was not published because no module with that name was found in any module directory.
PS> dotnet nuget push .\bin\MyModule.0.1.0.nupkg --api-key xxx --source https://www.powershellgallery.com/api/v2
Pushing MyModule.0.1.0.nupkg to 'https://www.powershellgallery.com/api/v2'...
PUT https://www.powershellgallery.com/api/v2/
MethodNotAllowed https://www.powershellgallery.com/api/v2/ 580ms
error: Response status code does not indicate success: 405 (Method Not Allowed).
Publishing .nupkg files to Powershell Gallery should be possible because you're able to download packages from Powershell Gallery as .nupkg files. Additionally, the Autorest documentation says this about its generated nupkg files:
The structure of the .nupkg is created so it can be loaded part of a PSRepository. Additionally, this package is in a format for distribution to the PSGallery.
I'm guessing this is possible, but I just can't figure out how to do it. Any help would be appreciated