Publish-Script -Path "path-to-script.ps1" -NuGetApiKey 123456789
这样做之后,我在PowerShell 7.3中得到这个错误:
Write-Error: Failed to generate the compressed file for script 'C:Program Filesdotnetdotnet.exe failed to pack: error '.
和我得到这个错误在PowerShell 5.1:
Publish-PSArtifactUtility : Failed to generate the compressed file for script 'C:Program Filesdotnetdotnet.exe
failed to pack: error
'.
At C:Program FilesWindowsPowerShellModulesPowerShellGet2.2.5PSModule.psm1:11338 char:17
+ ... Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : FailedToCreateCompressedScript,Publish-PSArtifactUtility
我的脚本没有依赖。
这个问题已经持续了两个星期了。
我甚至给了我的脚本与API密钥从另一个国家的朋友,他们也收到同样的错误。我怎样才能解决这个问题?在此之前,我已经发布了这个脚本的先前版本至少6次。
我已经尝试重置我的API密钥并以管理员身份运行PowerShell,但没有修复它。
更新:
我安装了。net 7运行时x64,并在PowerShell 5.1上使用了以下命令:
# find the file having wrong .NET version
$path = Get-ChildItem (Get-Module PowerShellGet -ListAvailable).ModuleBase -Recurse -File |
Select-String -Pattern netcoreapp2.0 | ForEach-Object Path
# unload the module
Remove-Module PowerShellGet -Verbose -Force -EA 0
# update the file
$path | ForEach-Object {
(Get-Content -LiteralPath $_ -Raw).Replace('netcoreapp2.0', 'net7') |
Set-Content $_
}
Import-Module PowerShellGet -Force -Verbose
# now try to publish
但仍然得到错误:
Publish-PSArtifactUtility : Failed to generate the compressed file for script 'C:Program Filesdotnetdotnet.exe
failed to pack: error
'.
At C:Program FilesWindowsPowerShellModulesPowerShellGet2.2.5PSModule.psm1:11338 char:17
+ ... Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : FailedToCreateCompressedScript,Publish-PSArtifactUtility
输入图片描述
我通过安装。net Core 2.0 SDK修复了这个问题
https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-2.1.202-windows-x64-installer