PowerShell / PSResourceGet

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

Repository 'PSGallery' is not a known repository type that is supported error when finding packages #1748

Closed variableresistor closed 2 weeks ago

variableresistor commented 2 weeks ago

Prerequisites

Steps to reproduce

 Find-PSResource -Name PSScriptAnalyzer

This works perfectly fine using the existing PowerShellGet module:

Find-Module -Name PSScriptAnalyzer

Here is a list of registered repositories:

Get-PSResourceRepository

Results in:

Name      Uri                                      Trusted Priority
----      ---                                      ------- --------
PSGallery https://www.powershellgallery.com/api/v2 True    50

Here's the contents of my PSResourceRepository.xml file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <Repository Name="PSGallery" Url="https://www.powershellgallery.com/api/v2" APIVersion="unknown" Priority="50" Trusted="True" />
</configuration>

Expected behavior

Should list the available modules in the PSGallery, just like Find-Module does with the below results:
Version              Name                                Repository           Description
-------              ----                                ----------           -----------
1.23.0               PSScriptAnalyzer                    PSGallery            PSScriptAnalyzer provides

Actual behavior

I get the error listed below. I've seen instances using NuGet where a misconfigured nuget.config file caused issues. So I checked my PSResourceRepository.xml:
It blows up and shows no search results. Same behavior with 
The contents are:

### Error details

```console
Exception             :
    Type    : Microsoft.PowerShell.PSResourceGet.UtilClasses.ResourceNotFoundException
    Message : Package 'PSScriptAnalyzer' 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        : 1
    Line             : Find-PSResource -Name PSScriptAnalyzer
    Statement        : Find-PSResource -Name PSScriptAnalyzer
    PositionMessage  : At line:1 char:1
                       + Find-PSResource -Name PSScriptAnalyzer
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Find-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
      0
      1

Environment data

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

Key   : PSVersion
Value : 7.4.6
Name  : PSVersion

Key   : PSEdition
Value : Core
Name  : PSEdition

Key   : GitCommitId
Value : 7.4.6
Name  : GitCommitId

Key   : OS
Value : Microsoft Windows 10.0.22631
Name  : OS

Key   : Platform
Value : Win32NT
Name  : Platform

Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0…}
Name  : PSCompatibleVersions

Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion

Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion

Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion

Visuals

No response

alerickson commented 2 weeks ago

Hi @variableresistor, please run Set-PSResourceRepository PSGallery -ApiVersion V2. I'm not sure how the ApiVersion got set to unknown but it should be v2 to interact with the PowerShell Gallery.

variableresistor commented 2 weeks ago

Yeah, totally surprised me too. And I work with NuGet repos all day. I wonder if it's some sort of default setting when installing PowerShell. I'll run that at the office tomorrow and will try it out on some other fresh Windows 11 machines.

variableresistor commented 2 weeks ago

That worked. Will reopen if it surfaces again on a fresh install.