【发布时间】:2021-05-20 20:37:14
【问题描述】:
解决方案
这是我最终将我的 bin\MyModule.0.1.0.nupkg 模块发布到 PSGallery 的操作:
- 将
bin\MyModule.0.1.0.nupkg重命名为bin\MyModule.0.1.0.zip - 提取
bin\MyModule.0.1.0.zip到bin\MyModule\(提取的文件夹的名称必须与里面的.psd1文件的名称匹配,所以在我的例子中,现在有一个bin\MyModule\MyModule.psd1文件)。 - 从提取的文件夹中删除
[Content_Types].xml文件(当您尝试从PSGallery下载和安装模块时,不删除此文件会导致错误,这似乎是由生成的.nupkg中存在该文件的2个副本引起的) .
然后我就可以运行这个命令了:
PS> Publish-Module -NuGetApiKey xxx -Path .\bin\MyModule
它奏效了!我的模块现已发布到 PSGallery。
原帖
我有一个由Autorest.Powershell 生成并打包为 .nupkg 文件的 Powershell 模块。我现在想将我的模块发布到Powershell Gallery,但不知道如何让它工作。 我试过了:
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).
应该可以将 .nupkg 文件发布到 Powershell Gallery,因为您可以从 Powershell Gallery 下载包为 .nupkg 文件。此外,Autorest 文档中提到了 this 关于其生成的 nupkg 文件:
.nupkg 的结构已创建,因此它可以作为 PSRepository 的一部分加载。此外,此软件包的格式可以分发到 PSGallery。
我猜这是可能的,但我就是不知道该怎么做。任何帮助将不胜感激
【问题讨论】:
-
我相信您尝试使用
Publish-Module执行此操作的方式要求不要打包模块。它会为你做包装。
标签: powershell autorest powershellget