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

Registering ProGet feeds fails-- Unknown Repository Default is not Desirable #1403

Open Jaykul opened 1 year ago

Jaykul commented 1 year ago

Prerequisites

Steps to reproduce

We've been using ProGet with no issues with PowerShellGet for years ...

image

$ServerDomain = "ProGet"
$FeedName  = "PowerShell"

Register-PSResourceRepository -Name $ServerDomain -Uri https://$ServerDomain/nuget/$FeedName -Trusted -Force
Install-PSResource $ModuleName -Repository $ServerDomain
Install-PSResource: Repository 'ProGet' is not a known repository type that is supported. Please file an issue for support at https://github.com/PowerShell/PSResourceGet/issues

Important:

I was able to get it to work by simply editing $Home\AppData\Local\PSResourceGet\PSResourceRepository.xml and replacing "unknown" with "v2" -- this is purely a bug in Register-PSResourceRepository which I don't understand.

Expected behavior

Register-PSResourceRepository should _just work_

Actual behavior

Register-PSResourceRepository put `APIVersion="unknown"` in the `PSResourceRepository.xml` file

Error details

Exception             :
    Type    : Microsoft.PowerShell.PSResourceGet.UtilClasses.ResourceNotFoundException
    Message : Package 'LDGit' could not be found in any registered repositories.
    HResult : -2146233088
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.FindHelper
CategoryInfo          : ObjectNotFound: (Microsoft.PowerShel….Cmdlets.FindHelper:FindHelper) [Find-PSResource], ResourceNotFoundException
FullyQualifiedErrorId : PackageNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource
InvocationInfo        :
    MyCommand        : Find-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 19
    Line             : Find-PSResource LDGit -Verbose -Debug
    Statement        : Find-PSResource LDGit -Verbose -Debug
    PositionMessage  : At line:1 char:1
                       + Find-PSResource LDGit -Verbose -Debug
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Find-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

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

Name                           Value
----                           -----
PSVersion                      7.4.0-preview.5
PSEdition                      Core
GitCommitId                    7.4.0-preview.5
OS                             Microsoft Windows 10.0.19042
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

We discussed this and determined that setting the api version value to a best guess is better than setting it to unknown if we can't for certain determine the API version (this wasn't a problem in PowerShellGet since only v2 was supported), if it is a guessed api version rather than known, we may want to emit a warning so the user can use the Set-PSResourceRepository cmdlet to update the ApiVersion if they themselves know the api version of the feed they are using and the guess is incorrect

Better documentation on the ApiVersion should be coming shortly

ThomasNieto commented 1 year ago

Can the cmdlet be updated to auto discover which version is in use? Try v3 first and then fall back to v2 and if that doesn't work make the API version unknown.

ephos commented 1 year ago

Have the same issue with Proget feeds. I am unsure if this comment should be here or in #1413 as there seems to be some overlap with them.

If I manually edit $Home\AppData\Local\PSResourceGet\PSResourceRepository.xml the work around from "unknown" to "v2" it allows Find-PSResource to work however the Name property is blank which will result in an error on Install-PSResource.

Output

Output of Find-PSResource -Name Pester -Repository GalleryProxy as I can't upload an image from this machine:

Name Version Prerelease Repository   Description
---- ------- ---------- ----------   -----------
     5.5.0              GalleryProxy Pester provides a framework for running BDD style Tests to execute and validate PowerShell commands inside of PowerShell and offers a powerful set of Mocking Functions that allow tests to mimic and mock the functionality of any command insid…

Errors

Piping to Install-PSResource (Get-Error output):

Exception             :
    Type    : Microsoft.PowerShell.PSResourceGet.UtilClasses.ResourceNotFoundException
    Message : Package(s) '' could not be installed from repository 'GalleryProxy'.
    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     : 59
    HistoryId        : 14
    Line             : Find-PSResource -Name Pester -Repository GalleryProxy | Install-PSResource
    PositionMessage  : At line:1 char:59
                       + … Resource -Name Pester -Repository GalleryProxy | Install-PSResource
                       +                                                      ~~~~~~~~~~~~~~~~~~
    InvocationName   : Install-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Running Install-PSResource directly (Get-Error output):

Exception             :
    Type       : System.NullReferenceException
    TargetSite :
        Name          : InstallVersion
        DeclaringType : Microsoft.PowerShell.PSResourceGet.Cmdlets.V2ServerAPICalls, Microsoft.PowerShell.PSResourceGet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
        MemberType    : Method
        Module        : Microsoft.PowerShell.PSResourceGet.dll
    Message    : Object reference not set to an instance of an object.
    Source     : Microsoft.PowerShell.PSResourceGet
    HResult    : -2147467261
    StackTrace :
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.V2ServerAPICalls.InstallVersion(String packageName, String version, ErrorRecord& errRecord)
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.V2ServerAPICalls.InstallPackage(String packageName, String packageVersion, Boolean includePrerelease, ErrorRecord& errRecord)
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallHelper.BeginPackageInstall(VersionType searchVersionType, NuGetVersion specificVersion, VersionRange versionRange, String pkgNameToInstall, PSRepositoryInfo repository, ServerApiCall currentServer, ResponseUtil
currentResponseUtil, String tempInstallPath, Hashtable packagesHash, ErrorRecord& errRecord)
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallHelper.InstallPackages(String[] pkgNamesToInstall, PSRepositoryInfo repository, ServerApiCall currentServer, ResponseUtil currentResponseUtil, ScopeType scope, Boolean skipDependencyCheck, FindHelper findHelper)
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallHelper.ProcessRepositories(String[] repository, Boolean trustRepository, Boolean skipDependencyCheck, ScopeType scope)
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallHelper.BeginInstallPackages(String[] names, VersionRange versionRange, NuGetVersion nugetVersion, VersionType versionType, String versionString, Boolean prerelease, String[] repository, Boolean acceptLicense, Boolean
quiet, Boolean reinstall, Boolean force, Boolean trustRepository, Boolean noClobber, Boolean asNupkg, Boolean includeXml, Boolean skipDependencyCheck, Boolean authenticodeCheck, Boolean savePkg, List`1 pathsToInstallPkg, Nullable`1 scope, String tmpPath, HashSet`1 pkgsInstalled)
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource.ProcessInstallHelper(String[] pkgNames, String pkgVersion, Boolean pkgPrerelease, String[] pkgRepository, PSCredential pkgCredential, InstallPkgParams reqResourceParams)
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
CategoryInfo          : NotSpecified: (:) [Install-PSResource], NullReferenceException
FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
InvocationInfo        :
    MyCommand        : Install-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 12
    Line             : Install-PSResource -Name Pester -Repository GalleryProxy
    PositionMessage  : At line:1 char:1
                       + Install-PSResource -Name Pester -Repository GalleryProxy
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Install-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     1.0.0                 Microsoft.PowerShell.PSResourceGet  {Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository, Get-PSScriptFileInfo…}
Name                           Value
----                           -----
PSVersion                      7.3.7
PSEdition                      Core
GitCommitId                    7.3.7
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

and

Name                           Value
----                           -----
PSVersion                      5.1.22621.1778
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.1778
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
ajansveld commented 8 months ago

It works if you update the uri to this: Register-PSResourceRepository -Name ProGet -Uri https://$ServerDomain/nuget/$FeedName/v3/index.json -Trusted

This is documented here: https://docs.inedo.com/docs/proget-feeds-nuget#using-the-nuget-api

ephos commented 8 months ago

@ajansveld I just tried to repro this on a connector based feed in ProGet (that proxies PSGallery) but any Find-PSResource/Install-PSResource return 404 when hitting ProGet's v3 URL.

Ran:

Install-PSResource -Name PSTcpIp -Repository GalleryProxy

Returned:

Install-PSResource: 'Response status code does not indicate success: 404 (Not Found).' Request sent: 'https://my.proget.instance/nuget/GalleryProxy/v3/index.json'
Install-PSResource: Package(s) 'PSTcpIp' could not be installed from repository 'GalleryProxy'.

Get-PSResourceRepository -Name GalleryProxy | Select-Object -Property *

Name           : GalleryProxy
Uri            : https://my.proget.instance/nuget/GalleryProxy/v3/index.json
Trusted        : True
Priority       : 50
CredentialInfo :
ApiVersion     : v3

Current ProGet Version: Version 2023.24 (Build 3)

Beyond using that v3 URL did you need do anything else?

Jaykul commented 8 months ago

To be clear, the Register-PSResourceRepository command always ran without errors, it just didn't put the right thing in $Home\AppData\Local\PSResourceGet\PSResourceRepository.xml

ajansveld commented 8 months ago

@ajansveld I just tried to repro this on a connector based feed in ProGet (that proxies PSGallery) but any Find-PSResource/Install-PSResource return 404 when hitting ProGet's v3 URL.

Beyond using that v3 URL did you need do anything else?

@ephos I don't think so, other than enabling JSON-LD (v3) api support for the endpoint of course. But our repo is not a PSGallery proxy.

Does this show your modules? (Invoke-RestMethod https://my.proget.instance/nuget/GalleryProxy/v3/search).data

ephos commented 5 months ago

@ajansveld unfortunately I no longer work at the organization that had Proget and can't check this.

ajansveld commented 5 months ago

@Jaykul do you believe this is still an issue? I cannot repro the problem (as long as the correct uri is used).

Jaykul commented 2 weeks ago

We can't just use v3/index.json when PSResourceGet doesn't support dependencies on v3 feeds.

Other than that ... I've completely stopped using this module pending a release that actually works.