如何解决使用 Publish-Script 时出现 Publish-PSArtifactUtility : 无法生成脚本压缩文件的错误?

问题描述 投票:0回答:1

我正在尝试将 PowerShell 脚本发布到

PSGallery
并且我过去已经成功发布了 PowerShell 模块,因此我的 API 密钥有效(甚至尝试更新它)。

Publish-Script -Path .\MyScript.ps1 -NuGetApiKey $ENV:MyKey
Publish-PSArtifactUtility : Failed to generate the compressed file for script 
'Attempting to build package from 'MyScript.nuspec'.'.  
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:2875
char:17
+ ...               Publish-PSArtifactUtility -PSScriptInfo $PSScriptInfo `
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : FailedToCreateCompressedScript,Publish-PSArtifactUtility

使用

-Verbose
输出将提供一些附加信息...

An error occured while trying to parse the value '' of property 'dependencies' in
the manifest file.
  '' is not a valid version string.

很明显,在生成的

MyScript.nuspec
文件的压缩过程中缺少一些值。

在尝试发布脚本之前,我添加了以下 ScriptInfo 参数。

param = @{
  Path = '.\MyScript.ps1'
  Version = '1.0.0'
  Author = 'Dennis'
  Description = 'My Script'
  ProjectUri = 'https://github.com/XXXXXX/MyScript'
  RequiredModules = 'PSWindowsUpdate',
    @{ModuleName='Pester';ModuleVersion='4.10.1'},
   'PendingReboot',
   'SpeculationControl'
}
Update-ScriptFileInfo @param -Force

(强烈推荐标签,但不是必需的。)

我已尝试以管理员身份更新

nuget.exe
,如下所示

Invoke-WebRequest `
  -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe `
  -OutFile "$env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe"

我可能错过了一些非常简单的东西,但不知道是什么......

powershell nuget-package publish
1个回答
0
投票

根据

PowerShellGet
中的 MS 支持
Windows PowerShell 5.1
不再支持
PS Gallery

所以我需要安装最新版本的

PowerShellGet

MS Learn - 更新 Windows PowerShell 5.1 的 PowerShellGet

所以解决方案是以管理员身份运行

Invoke-WebRequest `
  -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe `
  -OutFile "$env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe"

Install-Module PowerShellGet -AllowClobber -Force

然后重新启动 PowerShell 控制台。

© www.soinside.com 2019 - 2024. All rights reserved.