无法将脚本发布到PowerShell库,出现错误

gzszwxb4  于 2022-12-23  发布在  Shell
关注(0)|答案(1)|浏览(115)
Publish-Script -Path "path-to-script.ps1" -NuGetApiKey 123456789

完成此操作后,我在PowerShell 7.3中遇到此错误:

Write-Error: Failed to generate the compressed file for script 'C:\Program Files\dotnet\dotnet.exe failed to pack: error  '.

我在PowerShell 5.1中遇到了这个错误:

Publish-PSArtifactUtility : Failed to generate the compressed file for script 'C:\Program Files\dotnet\dotnet.exe
failed to pack: error
'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.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上使用了以下命令from this answer

# 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 Files\dotnet\dotnet.exe
failed to pack: error
'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:11338 char:17
+ ...             Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : FailedToCreateCompressedScript,Publish-PSArtifactUtility

enter image description here

相关问题