【问题标题】:Can't publish script to PowerShell gallery, getting error无法将脚本发布到 PowerShell 库,出现错误
【发布时间】:2022-12-04 23:57:57
【问题描述】:
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

【问题讨论】:

  • 在这里看看stackoverflow.com/q/74548911/15339544我认为你的问题可能与此有关
  • 我应该安装 .NET 运行时吗?
  • 不,请参阅答案,问题不在于您的 .NET 版本。问题是 PowerShellGet 团队没有正确更新他们的模块。
  • @SantiagoSquarzon 请看看我的问题,我更新了它。添加了 PowerShell 在模块中抱怨的确切部分的屏幕截图。

标签: powershell publish powershell-7.3


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 2019-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多