PowerShell / PSResourceGet

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

Install-PSResource from nuget Gallery fails #1334

Closed dy-nz closed 1 year ago

dy-nz commented 1 year ago

Prerequisites

Steps to reproduce

Hi, Using PWSH 7.3.6 on Windows Server 2019, Microsoft.PowerShell.PSResourceGet beta 23, and with the nuget Gallery Registered and Trusted using PWSH (nuget, https://www.nuget.org/api/v2), I have not been able to install any nuget package.

For example, the following command fails: Install-PSResource -Name itext -Scope AllUsers -Repository nuget

Thanks, David

Expected behavior

Successful install of nuget package and dependencies

Actual behavior

Excerpts from the warning and error message:

Install-PSResource: 'Response status code does not indicate success: 400 (Bad Request).' Request sent: 
VERBOSE: Parameters passed in >>> Name: 'itext'; VersionRange: ''; NuGetVersion: ''; VersionType: 'NoVersion'; Version: ''; Prerelease: 'False'; Repository: 'nuget'; AcceptLicense: 'False'; Quiet: 'False'; Reinstall: 'True'; TrustRepository: 'False'; NoClobber: 'False'; AsNupkg: 'False'; IncludeXml 'True'; SavePackage 'False'; TemporaryPath ''
VERBOSE: Attempting to search for packages in 'NuGet'
VERBOSE: Performing the operation "Install-PSResource" on target "Package to install: 'itext', version: '8.0.1'".
VERBOSE: This resource is not a PowerShell package and will be installed to the modules path: C:\Program Files\PowerShell\Modules.
VERBOSE: Deleting 'C:\Users\c0pta1n.HG\AppData\Local\Temp\936d83ec-563e-4dc2-a634-2c56b1ff6df6\itext\8.0.1\itext.nuspec'
VERBOSE: Deleting 'C:\Users\c0pta1n.HG\AppData\Local\Temp\936d83ec-563e-4dc2-a634-2c56b1ff6df6\itext\8.0.1\[Content_Types].xml'
VERBOSE: Deleting 'C:\Users\c0pta1n.HG\AppData\Local\Temp\936d83ec-563e-4dc2-a634-2c56b1ff6df6\itext\8.0.1\_rels'
VERBOSE: Deleting 'C:\Users\c0pta1n.HG\AppData\Local\Temp\936d83ec-563e-4dc2-a634-2c56b1ff6df6\itext\8.0.1\package'

'https://www.nuget.org/api/v2/FindPackagesById()?id='itext.commons'&$orderby=NormalizedVersion%20desc&$inlinecount=allpages&$skip=0&$filter=IsPrerelease%20eq%20false%20and%20Id%20eq%20'itext.commons'%20and%20NormalizedVersion%20ge%20'8.0.1'%20and%20NormalizedVersion%20le%20'8.1.0''

Error details

Exception             :
    Type       : System.Net.Http.HttpRequestException
    TargetSite :
        Name          : MoveNext
        DeclaringType : Microsoft.PowerShell.PSResourceGet.Cmdlets.V2ServerAPICalls+<SendV2RequestAsync>d__33,
Microsoft.PowerShell.PSResourceGet, Version=0.5.23.0, Culture=neutral, PublicKeyToken=null
        MemberType    : Method
        Module        : Microsoft.PowerShell.PSResourceGet.dll
    Message    : 'Response status code does not indicate success: 400 (Bad Request).' Request sent: 'https://www.nuget.
org/api/v2/FindPackagesById()?id='System.Text.RegularExpressions'&$orderby=NormalizedVersion%20desc&$inlinecount=allpag
es&$skip=0&$filter=IsPrerelease%20eq%20false%20and%20Id%20eq%20'System.Text.RegularExpressions'%20and%20NormalizedVersi
on%20ge%20'4.3.1'%20and%20NormalizedVersion%20le%20'4.4.0''
    Source     : Microsoft.PowerShell.PSResourceGet
    HResult    : -2146233088
    StackTrace :
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.V2ServerAPICalls.SendV2RequestAsync(HttpRequestMessage message,
HttpClient s_client)
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.V2ServerAPICalls.HttpRequestCall(String requestUrlV2, ErrorRecord&
errRecord)
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.V2ServerAPICalls
CategoryInfo          : ConnectionError: (Microsoft.PowerShel…ts.V2ServerAPICalls:V2ServerAPICalls)
[Install-PSResource], HttpRequestException
FullyQualifiedErrorId : HttpRequestCallFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
InvocationInfo        :
    MyCommand        : Install-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 37
    Line             : install-psresource -name itext -scope allusers -repository nuget -reinstall -verbose
    PositionMessage  : At line:1 char:1
                       + install-psresource -name itext -scope allusers -repository nuget -rei …
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : install-psresource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     0.5.23     beta23     Microsoft.PowerShell.PSResourceGet  {Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository, Get-PSScriptFileInfo…}

Name                           Value
----                           -----
PSVersion                      7.3.6
PSEdition                      Core
GitCommitId                    7.3.6
OS                             Microsoft Windows 10.0.20348
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

SydneyhSmith commented 1 year ago

Hi @dy-nz thanks for opening this issue, I think the issue maybe that you need to use a v3 endpoint to interact with nuget...try setting the uri as "https://api.nuget.org/v3/index.json"

In other words run Set-PSResourceRepository nuget -uri "https://api.nuget.org/v3/index.json" -ApiVersion v3

dy-nz commented 1 year ago

Hi Sydney, thanks very much. Thought it might be the case but couldn't find documentation anywhere. Installing from nuget using Install-PSResource has thrown up two problems, which I've opened separate issues for. Looking forward to support for dependencies :-)

Thanks for the fantastic new solution. David