如果你在PowerShell Core中无法使用Publish-Module发布NuGet模块

可以检查一下是不是因为你的.NET Core CLI正在使用非英语输出。Publish-Module需要根据.NET Core CLI的输出来匹配生成的NuGet包的位置。

在Publish-Module调用后面加上-Verbose参数即可显示.NET Core CLI的输出信息,例如

PS> Publish-Module -Path:$RedistDir -Repository:$RepositoryName -NuGetApiKey:$ApiKey -Verbose
VERBOSE: Acquiring providers for assembly: C:\program files\powershell\7-preview\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.ArchiverProviders.dll
VERBOSE: Acquiring providers for assembly: C:\program files\powershell\7-preview\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.CoreProviders.dll
VERBOSE: Acquiring providers for assembly: C:\program files\powershell\7-preview\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.MetaProvider.PowerShell.dll
VERBOSE: Acquiring providers for assembly: C:\program files\powershell\7-preview\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.NuGetProvider.dll
VERBOSE: Repository details, Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2'; IsTrusted = 'False'; IsRegistered = 'True'.
VERBOSE: Repository details, Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2'; IsTrusted = 'False'; IsRegistered = 'True'.
VERBOSE: Publish Location:'https://www.powershellgallery.com/api/v2/package/'.
VERBOSE: Module 'PSMWUpdater' was found in 'E:\My Files\Visual Studio 2019\Projects\PSMWUpdater\PSMWUpdater\bin\Redist\PSMWUpdater'.
VERBOSE: Repository details, Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2'; IsTrusted = 'False'; IsRegistered = 'True'.
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: Using the specified source names : 'PSGallery'.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2/items/psscript' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/items/psscript/FindPackagesById()?id='PSMWUpdater'' for ''.
VERBOSE: Total package yield:'0' for the specified package 'PSMWUpdater'.
VERBOSE: Repository details, Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2'; IsTrusted = 'False'; IsRegistered = 'True'.
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: Using the specified source names : 'PSGallery'.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PSMWUpdater'' for ''.
VERBOSE: Total package yield:'0' for the specified package 'PSMWUpdater'.
VERBOSE: Performing the operation "Publish-Module" on target "Version '1.0.0' of module 'PSMWUpdater'".
VERBOSE: Calling Publish-PSArtifactUtility
VERBOSE: Calling New-NuspecFile
VERBOSE: Calling New-NugetPackage
VERBOSE: Calling C:\Program Files\dotnet\dotnet.exe pack "~\AppData\Local\Temp\617ee336-a326-444e-b627-e5f73281abbd\Temp.csproj" /p:NuspecFile="~\AppData\Local\Temp\1937237968\PSMWUpdater\PSMWUpdater.nuspec" --output "~\AppData\Local\Temp\1937237968\PSMWUpdater"
VERBOSE: C:\Program Files\dotnet\dotnet.exe output:
VERBOSE:        用于 .NET Core 的 Microsoft (R) 生成引擎版本 16.4.0+e901037fe
VERBOSE:        版权所有(C) Microsoft Corporation。保留所有权利。
VERBOSE:
VERBOSE:          ~\AppData\Local\Temp\617ee336-a326-444e-b627-e5f73281abbd\Temp.csproj 的还原在 221.27 ms 内完成。
VERBOSE:          Temp -> ~\AppData\Local\Temp\617ee336-a326-444e-b627-e5f73281abbd\bin\Debug\netcoreapp2.0\NotUsed.dll
VERBOSE:          已成功创建包“~\AppData\Local\Temp\1937237968\PSMWUpdater\PSMWUpdater.1.0.0.nupkg”。
VERBOSE:        C:\Program Files\dotnet\sdk\3.1.100\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5100: 程序集“AsyncEnumerableExtensions.dll”不在 "lib" 文件夹
内,因此将包安装到项目中后,不能将该程序集添加为引用。如需引用,请将其移动到 "lib" 文件夹。 [~\AppData\Local\Temp\617ee336-a326-444e-b627-e5f73281abbd\Temp.csproj]
VERBOSE:        C:\Program Files\dotnet\sdk\3.1.100\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5100: 程序集“Microsoft.Extensions.Logging.Abstractions.dll” 
不在 "lib" 文件夹内,因此将包安装到项目中后,不能将该程序集添加为引用。如需引用,请将其移动到 "lib" 文件夹。 [~\AppData\Local\Temp\617ee336-a326-444e-b627-e5f73281abbd\Temp.csproj]    
VERBOSE:        C:\Program Files\dotnet\sdk\3.1.100\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5100: 程序集“Newtonsoft.Json.dll”不在 "lib" 文件夹内,因此将
包安装到项目中后,不能将该程序集添加为引用。如需引用,请将其移动到 "lib" 文件夹。 [~\AppData\Local\Temp\617ee336-a326-444e-b627-e5f73281abbd\Temp.csproj]
VERBOSE:        C:\Program Files\dotnet\sdk\3.1.100\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5100: 程序集“PSMWUpdater.dll”不在 "lib" 文件夹内,因此将包安
装到项目中后,不能将该程序集添加为引用。如需引用,请将其移动到 "lib" 文件夹。 [~\AppData\Local\Temp\617ee336-a326-444e-b627-e5f73281abbd\Temp.csproj]
VERBOSE:        C:\Program Files\dotnet\sdk\3.1.100\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5100: 程序集“System.Interactive.Async.dll”不在 "lib" 文件夹 
内,因此将包安装到项目中后,不能将该程序集添加为引用。如需引用,请将其移动到 "lib" 文件夹。 [~\AppData\Local\Temp\617ee336-a326-444e-b627-e5f73281abbd\Temp.csproj]
VERBOSE:        C:\Program Files\dotnet\sdk\3.1.100\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5100: 程序集“System.Linq.dll”不在 "lib" 文件夹内,因此将包安
装到项目中后,不能将该程序集添加为引用。如需引用,请将其移动到 "lib" 文件夹。 [~\AppData\Local\Temp\617ee336-a326-444e-b627-e5f73281abbd\Temp.csproj]
VERBOSE:        C:\Program Files\dotnet\sdk\3.1.100\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5100: 程序集“System.Management.Automation.dll”不在 "lib" 文 
件夹内,因此将包安装到项目中后,不能将该程序集添加为引用。如需引用,请将其移动到 "lib" 文件夹。 [~\AppData\Local\Temp\617ee336-a326-444e-b627-e5f73281abbd\Temp.csproj]
VERBOSE:        C:\Program Files\dotnet\sdk\3.1.100\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5100: 程序集“System.Threading.dll”不在 "lib" 文件夹内,因此
将包安装到项目中后,不能将该程序集添加为引用。如需引用,请将其移动到 "lib" 文件夹。 [~\AppData\Local\Temp\617ee336-a326-444e-b627-e5f73281abbd\Temp.csproj]
VERBOSE:        C:\Program Files\dotnet\sdk\3.1.100\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): warning NU5100: 程序集“WikiClientLibrary.dll”不在 "lib" 文件夹内,因此
将包安装到项目中后,不能将该程序集添加为引用。如需引用,请将其移动到 "lib" 文件夹。 [~\AppData\Local\Temp\617ee336-a326-444e-b627-e5f73281abbd\Temp.csproj]
VERBOSE: finished running C:\Program Files\dotnet\dotnet.exe with exit code 0
Write-Error: C:\program files\powershell\7-preview\Modules\PowerShellGet\PSModule.psm1
 Line |
10944 |                 Publish-PSArtifactUtility @PublishPSArtifactUtility_Params
      |                 ^ Failed to generate the compressed file for module 'Cannot index into a null array.'.

请注意35行的输出。如果你发现.NET Core CLI正在输出非英语文本,你需要转到PowerShellGet报错的模块中(如此处的 C:\program files\powershell\7-preview\Modules\PowerShellGet\PSModule.psm1),搜索以下文本

"Successfully created package '(.*.nupkg)'"

并将其替换为当前系统语言对应的文本,如

'已成功创建包“(.*.nupkg)”'

最后重新打开PowerShell Core并进行模块发布即可。

此问题在PowerShell/PowerShellGetv2#510中提及,但在发布的PowerShell Core 7.0中仍然存在。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

ERROR: si-captcha.php plugin: GD image support not detected in PHP!

Contact your web host and ask them to enable GD image support for PHP.

ERROR: si-captcha.php plugin: imagepng function not detected in PHP!

Contact your web host and ask them to enable imagepng for PHP.

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

Content is available under CC BY-SA 3.0 unless otherwise noted.