I'm trying to publish a PowerShell script to PSGallery
and I have successfully published PowerShell modules in the past, so my API key works (even tried renewing it).
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
Using -Verbose
output will provide some additional information...
An error occured while trying to parse the value '' of property 'dependencies' in
the manifest file.
'' is not a valid version string.
So clearly some value is missing during the compression process in the generated MyScript.nuspec
file.
I've added the following ScriptInfo parameters before trying to publish the script.
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
(Tags are strongly recommeded but not a requirement.)
I've tried updating nuget.exe
as Administrator as found here
Invoke-WebRequest `
-Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe `
-OutFile "$env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe"
I've probably missed something really simple, but can't figure out what...
According to MS Suppport PowerShellGet
in Windows PowerShell 5.1
is no longer supported with PS Gallery
.
So I needed to install the latest version of PowerShellGet
.
MS Learn - Update PowerShellGet for Windows PowerShell 5.1
So the solution would be to run this as Admin
Invoke-WebRequest `
-Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe `
-OutFile "$env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe"
Install-PackageProvider -Name NuGet -Force
Install-Module PowerShellGet -AllowClobber -Force
(The manual nuget download might be redundant, I haven't checked.)
and then restart the PowerShell console.