PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
483 stars 92 forks source link

`Install-PSResource`: Fail to install module when passing `-Version` (range) together with `-Prerelease` #1677

Closed johlju closed 1 week ago

johlju commented 1 month ago

Prerequisites

Steps to reproduce

This should be reproduced using a module's major version that only has prereleases. That is the current state of Pester v6 for now.

Install-PSResource -Name 'Pester' -Version '[6.0,7.0)' -Prerelease

Expected behavior

PS> Install-PSResource -Name 'Pester' -Version '[6.0,7.0)' -Prerelease
PS> # Successfully installed Pester v6.0.0-alpha4 correctly (or any other 6.0 version that is the latest)

Actual behavior

PS> Install-PSResource -Name 'Pester' -Version '[6.0,7.0)' -Prerelease
Install-PSResource: Package(s) 'Pester' could not be installed from repository 'PSGallery'.

Error details

Type        : System.Management.Automation.ActionPreferenceStopException
ErrorRecord :
    Exception             :
        Type    : Microsoft.PowerShell.PSResourceGet.UtilClasses.ResourceNotFoundException
        Message : Package(s) 'Pester' could not be installed from repository 'PSGallery'.
        HResult : -2146233088
    TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
    CategoryInfo          : InvalidData: (Microsoft.PowerShel…s.InstallPSResource:InstallPSResource) [Install-PSResource], ResourceNotFoundException
    FullyQualifiedErrorId : InstallPackageFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
    InvocationInfo        :
        MyCommand        : Install-PSResource
        ScriptLineNumber : 1
        OffsetInLine     : 1
        HistoryId        : 40
        Line             : Install-PSResource -Name 'Pester' -Version '[6.0,7.0)' -TrustRepository -ErrorAction 'Stop' -Confirm:$false -PassThru
-Quiet
        Statement        : Install-PSResource -Name 'Pester' -Version '[6.0,7.0)' -TrustRepository -ErrorAction 'Stop' -Confirm:$false -PassThru
-Quiet
        PositionMessage  : At line:1 char:1
                           + Install-PSResource -Name 'Pester' -Version '[6.0,7.0)' -TrustReposito …
                           + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        InvocationName   : Install-PSResource
        CommandOrigin    : Internal
    ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    PipelineIterationInfo :
              0
              1
TargetSite  :
    Name          : Invoke
    DeclaringType : [System.Management.Automation.Runspaces.PipelineBase]
    MemberType    : Method
    Module        : System.Management.Automation.dll
Message     : The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Package(s)
'Pester' could not be installed from repository 'PSGallery'.
Data        : System.Collections.ListDictionaryInternal
Source      : System.Management.Automation
HResult     : -2146233087
StackTrace  :
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at Microsoft.PowerShell.Executor.ExecuteCommandHelper(Pipeline tempPipeline, Exception& exceptionThrown, ExecutionOptions options)

Environment data

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     1.0.5                 Microsoft.PowerShell.PSResourceGet  {Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository, Get-PSScri…

Name                           Value
----                           -----
PSVersion                      7.4.3
PSEdition                      Core
GitCommitId                    7.4.3
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

o-l-a-v commented 1 month ago

Use -Verbose and/or -Debug (don't remember which) to see what API query against PowerShell Gallery the cmdlet generates. Could be a problem with the PowerShell Gallery, lots of open issues about it in the PowerShell Gallery repo:


Edit:

Find-PSResource -Repository 'PSGallery' -Name 'Pester' -Version '[6.0,7.0)' -Prerelease -Debug

gives URL:

Using the API directly returns four alpha versions:

PS > Invoke-RestMethod -Method 'Get' -Uri 'https://www.powershellgallery.com/api/v2/FindPackagesById()?$filter=NormalizedVersion+ge+%276.0.0%27+and+NormalizedVersion+lt+%277.0.9%27+and+Id+eq+%27Pester%27&$inlinecount=allpages&$skip=0&$orderby=NormalizedVersion+desc&id=%27Pester%27'

id         : https://www.powershellgallery.com/api/v2/Packages(Id='Pester',Version='6.0.0-alpha4')
category   : category
link       : {link, link}
title      : title
updated    : 2024-07-11T19:05:03Z
author     : author
content    : content
properties : properties

id         : https://www.powershellgallery.com/api/v2/Packages(Id='Pester',Version='6.0.0-alpha3')
category   : category
link       : {link, link}
title      : title
updated    : 2024-07-05T13:27:38Z
author     : author
content    : content
properties : properties

id         : https://www.powershellgallery.com/api/v2/Packages(Id='Pester',Version='6.0.0-alpha2')
category   : category
link       : {link, link}
title      : title
updated    : 2024-07-01T14:16:32Z
author     : author
content    : content
properties : properties

id         : https://www.powershellgallery.com/api/v2/Packages(Id='Pester',Version='6.0.0-alpha1')
category   : category
link       : {link, link}
title      : title
updated    : 2024-07-11T03:34:51Z
author     : author
content    : content
properties : properties

PS >

So this actually might be a bug with PSResourceGet?

SydneyhSmith commented 1 week ago

Thanks @johlju nuget version ranges consider an alpha version of 6 to be below 6.0