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

PSResourceGet does not work with NuGet.Server #1206

Closed sdwheeler closed 1 year ago

sdwheeler commented 1 year ago

Prerequisites

Steps to reproduce

I follow the instructions for setting up a local instance of NuGet.Server we have in Working with Private PowerShellGet Repositories.

I used Visual Studio 2022. I had to add the .NET Framework development tools. You need this so that you can create a new "ASP.NET Web Application (.NET Framework)" project.

For testing, you have to create a self-signed certificate and add it to your trusts. I had trouble getting Edge to display the page for the URL but got it to work in Chrome.

Once the NuGet.Server instance was running:

Next I tested with PowerShellGet v2.2.5. V2.2.5 was able to find the package.

Expected behavior

The PSResourceGet cmdlets should work with NuGet.Server.

Actual behavior

Testing with PSResourceGet

PS> Find-PSResource -name PSStyle -Repository localhost
Find-PSResource: Object reference not set to an instance of an object.

Testing with PowerShellGet v2.2.5

PS> pwsh -noprofile
PowerShell 7.4.0-preview.3
PS D:\Git\PS-Docs\PowerShell-Docs-PSGet> ipmo powershellGet -RequiredVersion 2.2.5
PS D:\Git\PS-Docs\PowerShell-Docs-PSGet> find-module PSStyle -Repository localhost

Version     Name           Repository     Description
-------     ----           ----------     -----------
1.1.5       PSStyle        localhost      This module creates the `$PSStyle` varia…

Error details

PS> get-error

Exception             :
    Type       : System.NullReferenceException
    TargetSite :
        Name          : MoveNext
        DeclaringType : Microsoft.PowerShell.PowerShellGet.Cmdlets.FindHelper+<SearchByNames>d__19, PowerShellGet,
Version=3.0.21.0, Culture=neutral, PublicKeyToken=null
        MemberType    : Method
        Module        : PowerShellGet.dll
    Message    : Object reference not set to an instance of an object.
    Source     : PowerShellGet
    HResult    : -2147467261
    StackTrace :
   at Microsoft.PowerShell.PowerShellGet.Cmdlets.FindHelper.SearchByNames(ServerApiCall currentServer, ResponseUtil
currentResponseUtil, PSRepositoryInfo repository)+MoveNext()
   at Microsoft.PowerShell.PowerShellGet.Cmdlets.FindHelper.FindByResourceName(String[] name, ResourceType type,
VersionRange versionRange, NuGetVersion nugetVersion, VersionType versionType, String version, Boolean prerelease,
String[] tag, String[] repository, Boolean includeDependencies)+MoveNext()
   at Microsoft.PowerShell.PowerShellGet.Cmdlets.FindPSResource.ProcessResourceNameParameterSet()
   at Microsoft.PowerShell.PowerShellGet.Cmdlets.FindPSResource.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
CategoryInfo          : NotSpecified: (:) [Find-PSResource], NullReferenceException
FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.PowerShellGet.Cmdlets.FindPSResource
InvocationInfo        :
    MyCommand        : Find-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 378
    Line             : Find-PSResource -name PSStyle -Repository localhost
    Statement        : Find-PSResource -name PSStyle -Repository localhost
    PositionMessage  : At line:1 char:1
                       + Find-PSResource -name PSStyle -Repository localhost
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Find-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

PowerShell 7.4-p3

Visuals

No response

sdwheeler commented 1 year ago

NOTE: NuGet.Server has existed since 2016 and we have supported for as long as I have been doing the PowerShell docs. There have been over 495,000 downloads of the NuGet.Server package. I think that it is important to support NuGet.Server.

SydneyhSmith commented 1 year ago

@sdwheeler thanks for opening this issue, we are doing some testing, and want to see if https://localhost:44370/api/v2 works as a uri for you? This doesn't give v3 support but may be a quick work around for v2 support

sdwheeler commented 1 year ago

@sdwheeler thanks for opening this issue, we are doing some testing, and want to see if https://localhost:44370/api/v2 works as a uri for you? This doesn't give v3 support but may be a quick work around for v2 support

Nope, I get the same error. When I try to browse to that url I get a 404 error. When I browse to the documented endpoint https://localhost:44370/nuget I get the following XML response.

<service xmlns="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom" xml:base="https://localhost:44370/nuget">
  <workspace>
    <atom:title type="text">Default</atom:title>
    <collection href="Packages">
      <atom:title type="text">Packages</atom:title>
    </collection>
  </workspace>
</service>