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

Find-PSResource not working with ProGet (Find-Module does) #1413

Open Jaykul opened 1 year ago

Jaykul commented 1 year ago

Prerequisites

Steps to reproduce

Using Find-PSResource against our ProGet repository returns modules with the Name not populated, and if the module isn't also available in another feed, produces an error claiming it didn't find anything (even though it showed me the version and everything else).

Using Install-PSResource fails, because the name is blank when it tries to install, so it says something like:

VERBOSE: Performing the operation "Install-PSResource" on target "Package to install: '', version: '1.0.2'".

Expected behavior

Find-PSResource should return the right metadata and not error when the module exists.

Install-PSResource should install

Actual behavior

Find-Module works fine, but Find-PSResource does not.

Install-Module works fine, but Install-PSResource does not.

Error details

Microsoft.PowerShell.PSResourceGet\Find-PSResource LDEnvironments | Format-List

AdditionalMetadata       : {[NormalizedVersion, 1.0.2]}
Author                   :
CompanyName              :
Copyright                : Copyright 2023 loanDepot.com, LLC
Dependencies             : {}
Description              : The core loanDepot environment configuration
IconUri                  :
Includes                 : Microsoft.PowerShell.PSResourceGet.UtilClasses.ResourceIncludes
InstalledDate            :
InstalledLocation        :
IsPrerelease             : False
LicenseUri               :
Name                     :
Prerelease               :
ProjectUri               :
PublishedDate            : 9/21/2023 6:37:31 PM
ReleaseNotes             : LDEnvironments v1.0.2+Build.66011.Branch.main.Sha.448f19d5975533ec2db5c3096f47dc66b205f04a.Date.20230921T223524
Repository               : DevOpsPowerShell
RepositorySourceLocation : https://nuget.loandepot.com/nuget/PowerShell
Tags                     : {PSModule, PSIncludes_Function, PSFunction_Get-LDEnvironment, PSCommand_Get-LDEnvironment}
Type                     : Module
UpdatedDate              :
Version                  : 1.0.2

Find-PSResource: Package 'LDEnvironments' could not be found in any registered repositories.

When calling install:

Microsoft.PowerShell.PSResourceGet\Install-PSResource -Name LDEnvironments -Verbose
...
VERBOSE: Performing the operation "Install-PSResource" on target "Package to install: '', version: '1.0.2'".
VERBOSE: Attempting to delete 'C:\Users\joelbennett\AppData\Local\Temp\6db6a622-fc69-4ff9-8b06-9eb1225d2efc'
VERBOSE: Successfully deleted 'C:\Users\joelbennett\AppData\Local\Temp\6db6a622-fc69-4ff9-8b06-9eb1225d2efc'
Install-PSResource: Object reference not set to an instance of an object.

### Environment data

```powershell
**NOTE:** We _are_ out of date on ProGet, but ... the old module(s) work.
We're on ProGet Version 6.0.8 (Build 5)

----

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

image image

SydneyhSmith commented 1 year ago

Thanks @Jaykul for testing and reporting--we are looking into it, to confirm what APIVersion did you set the repo to (looked like in the other issue it was v2)?

Jaykul commented 1 year ago

Yeah, I tried switching to v3 to try to fix the other problem, but it didn't seem to help, so I'm hitting the v2 API

wsmelton commented 1 year ago

You can see in debug logs on the Install call since the first request to find the package isn't returning the name, the URL to install is coming up as: https://<host>/nuget/PowerShell/package//{semver}

image

This is using v1.0.0 of the PSResource module.

Jaykul commented 11 months ago

Yep. I'm seeing that same thing.

In 1.0.1 Find-PSResource finds the module (and also produces an error that says it can't find it in any registered repository, since it couldn't find it in PSGallery)...

But when I try to install, it finds it, then forgets the name (prompts for confirmation) and fails to install it:

Install-PSResource LDGitOps -Verbose -Debug
VERBOSE: Attempting to search for packages in 'DevOpsPowerShell'
DEBUG: In InstallHelper::InstallPackages()
DEBUG: In InstallHelper::InstallPackage()
DEBUG: In V2ServerAPICalls::FindName()
DEBUG: In V2ServerAPICalls::HttpRequestCall()
DEBUG: Request url is 'https://nuget.loandepot.com/nuget/PowerShell/FindPackagesById()?id='LDGitOps'&$inlinecount=allpages&$filter=IsLatestVersion and Id eq 'LDGitOps''

Confirm
Are you sure you want to perform this action?
Performing the operation "Install-PSResource" on target "Package to install: '', version: '1.0.0'".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
DEBUG: In V2ServerAPICalls::InstallVersion()
DEBUG: In V2ServerAPICalls::HttpRequestCallForContent()
DEBUG: Request url is 'https://nuget.loandepot.com/nuget/PowerShell/package//1.0.0'
DEBUG: Response is empty
VERBOSE: Attempting to delete 'C:\Users\joelbennett\AppData\Local\Temp\409f4769-1452-4242-9040-e61812622536'
VERBOSE: Successfully deleted 'C:\Users\joelbennett\AppData\Local\Temp\409f4769-1452-4242-9040-e61812622536'
Install-PSResource: Object reference not set to an instance of an object.
jjolidon commented 7 months ago

Hi all, I'm also hit by this one.

jjolidon commented 7 months ago

I did some more debugging, and I find that the issue might well be on ProGet's side, with an additional fix that could solve the issue on your side. ProGet's response to the FindPackagesById includes both a title and a `m:properties/d:Title tag (where d is xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices") - but the properties/Title tag is empty.

I'm surprised, as looking at the code I would have thought that second empty title would be ignored. I'm using 1.0.3 at the moment, FYI. Here is an anonymized sample output:


<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="https://proget.example.org/nuget/FeedName/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Packages</title>
  <id>https://proget.example.org/nuget/FeedName/FindPackagesById()/</id>
  <updated>2024-03-15T14:35:09Z</updated>
  <link rel="self" title="FindPackagesById" href="FindPackagesById" />
  <m:count>1
  </m:count>
  <entry>
    <id>https://proget.example.org/nuget/FeedName/Packages(Id='PackageName',Version='1.2.3')</id>
    <title type="text">PackageName</title>
    <summary type="text"></summary>
    <updated>2024-02-06T22:38:37Z</updated>
    <author>
      <name>Author LTD</name>
    </author>
    <link rel="edit-media" title="Package" href="Packages(Id='PackageName',Version='1.2.3')/$value" />
    <link rel="edit" title="Package" href="Packages(Id='PackageName',Version='1.2.3')" />
    <category term="NuGet.Server.DataServices.Package" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/zip" src="https://proget.example.org/nuget/FeedName/package/PackageName/1.2.3" />
    <m:properties xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
      <d:Version>1.2.3</d:Version>
      <d:Title></d:Title>
      <!-- Other fields omitted -->
    </m:properties>
  </entry>
</feed>
jjolidon commented 7 months ago

I'll go ahead and report this to Inedo.