PowerShell / PowerShellGetv2

PowerShellGet is the Package Manager for PowerShell
https://www.PowerShellGallery.com
MIT License
430 stars 138 forks source link

Find-Module -AllVersions does not produce output #604

Open phonegi opened 4 years ago

phonegi commented 4 years ago

A Windows PowerShell v5.1 session:

PS H:\> $PSVersionTable

Name                           Value                                                                                                                                                                                                                             
----                           -----                                                                                                                                                                                                                             
PSVersion                      5.1.17763.1007                                                                                                                                                                                                                    
PSEdition                      Desktop                                                                                                                                                                                                                           
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                                           
BuildVersion                   10.0.17763.1007                                                                                                                                                                                                                   
CLRVersion                     4.0.30319.42000                                                                                                                                                                                                                   
WSManStackVersion              3.0                                                                                                                                                                                                                               
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                                               
SerializationVersion           1.1.0.1                                                                                                                                                                                                                           

PS H:\> Import-Module PowerShellGet

PS H:\> Get-Module PowerShellGet

ModuleType Version    Name                                ExportedCommands                                                                                                                                                                                       
---------- -------    ----                                ----------------                                                                                                                                                                                       
Script     2.2.4.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}                                                                                                                                  

PS H:\> Get-PSRepository

Name                      InstallationPolicy   SourceLocation                                                                                                                                                                                                    
----                      ------------------   --------------                                                                                                                                                                                                    
LocalPSRepo               Trusted              C:\Users\xxx\Documents\PowerShell\Local Repository\                                                                                                                                                           
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2                                                                                                                                                                          
NetworkPSRepo             Trusted              H:\PowerShell\Repository\                                                                                                                                                                                         

PS H:\> dir H:\PowerShell\Repository

    Directory: H:\PowerShell\Repository

Mode                LastWriteTime         Length Name                                                                                                                                                                                                            
----                -------------         ------ ----                                                                                                                                                                                                            
-a----         5/4/2020   2:54 PM           3577 DBModule.1.0.nupkg                                                                                                                                                                                              
-a----         5/4/2020   2:55 PM           3584 DBModule.1.1.nupkg                                                                                                                                                                                              

PS H:\> Find-Module DBModule -AllVersions

PS H:\> Find-Module DBModule -Repository NetworkPSRepo -AllVersions -Verbose
VERBOSE: Repository details, Name = 'NetworkPSRepo', Location = 'H:\PowerShell\Repository\'; IsTrusted = 'True'; IsRegistered = 'True'.
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: Using the specified source names : 'NetworkPSRepo'.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'H:\PowerShell\Repository\' and PackageManagementProvider is 'NuGet'.
VERBOSE: Total package yield:'2' for the specified package 'DBModule'.

PS H:\> Remove-Module PowerShellGet

PS H:\> Import-Module PowerShellGet -RequiredVersion 1.0.0.1

PS H:\> Get-Module PowerShellGet

ModuleType Version    Name                                ExportedCommands                                                                                                                                                                                       
---------- -------    ----                                ----------------                                                                                                                                                                                       
Script     1.0.0.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}                                                                                                                                  

PS H:\> Find-Module DBModule -AllVersions

Version    Name                                Repository           Description                                                                                                                                                                                  
-------    ----                                ----------           -----------                                                                                                                                                                                  
1.1        DBModule                            NetworkPSRepo        PowerShell wrappers for .NET Form classes                                                                                                                                                    
1.0        DBModule                            NetworkPSRepo        PowerShell wrappers for .NET Form classes                                                                                                                                                    

A PowerShell Core 6.0 session:

PS C:\Program Files\PowerShell\6.0.1> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.1
PSEdition                      Core
GitCommitId                    v6.0.1
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS C:\Program Files\PowerShell\6.0.1> Import-Module PowerShellGet

PS C:\Program Files\PowerShell\6.0.1> Get-Module PowerShellGet

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     2.2.4.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}

PS C:\Program Files\PowerShell\6.0.1> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2
LocalPSRepo               Trusted              C:\Users\xxx\Documents\PowerShell\Local Repository\
NetworkPSRepo             Trusted              H:\PowerShell\Repository\

PS C:\Program Files\PowerShell\6.0.1> dir H:\PowerShell\Repository

    Directory: H:\PowerShell\Repository

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         5/4/2020   2:54 PM           3577 DBModule.1.0.nupkg
-a----         5/4/2020   2:55 PM           3584 DBModule.1.1.nupkg

PS C:\Program Files\PowerShell\6.0.1> Find-Module DBModule -AllVersions

PS C:\Program Files\PowerShell\6.0.1> Find-Module DBModule -Repository NetworkPSRepo -AllVersions -Verbose
VERBOSE: Repository details, Name = 'NetworkPSRepo', Location = 'H:\PowerShell\Repository\'; IsTrusted = 'True'; IsRegistered = 'True'.
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: Using the specified source names : 'NetworkPSRepo'.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'H:\PowerShell\Repository\' and PackageManagementProvider is 'NuGet'.
VERBOSE: Total package yield:'2' for the specified package 'DBModule'.

PS C:\Program Files\PowerShell\6.0.1> Remove-Module PowerShellGet

PS C:\Program Files\PowerShell\6.0.1> Import-Module PowerShellGet -RequiredVersion 1.1.0.0

PS C:\Program Files\PowerShell\6.0.1> Get-Module PowerShellGet

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.1.0.0    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}

PS C:\Program Files\PowerShell\6.0.1> Find-Module DBModule -AllVersions

Version    Name                                Repository           Description
-------    ----                                ----------           -----------
1.1        DBModule                            NetworkPSRepo        PowerShell wrappers for .NET Form classes
1.0        DBModule                            NetworkPSRepo        PowerShell wrappers for .NET Form classes
FISHMANPET commented 4 years ago

I came across something like this just now. Out of curiosity, does it work if you specify add -AllowPrerelease to your search? It's not likely to be fixed, but I think I found a bug here: https://github.com/PowerShell/PowerShellGetv2/blob/8c61ce7687de813438b0698c6eb461f610aa25ca/src/PowerShellGet/public/psgetfunctions/Find-Module.ps1#L158 Specifically this part $psgetItemInfo.AdditionalMetadata.IsPrerelease -eq 'false'. For a package that isn't prerelease, I don't think the AdditionalMetadata will have an IsPrerelease property, so $psgetItemInfo.AdditionalMetadata.IsPrerelease will return $null, so it essentially boils down to $null -eq 'false' which is itself false, so it won't execute the part of the code that will return the package. So it will accidentally filter out every package unless you specify -AllowPrerelease which will then also return PreRelease packages.

Easy enough to fix, assuming my assumption that Find-Package won't set an IsPrerelease property when it's not prerelease. But I doubt it will happen since all the work is happening on v3.

MarkKharitonov commented 3 years ago

For a package that isn't prerelease $psgetItemInfo.AdditionalMetadata.IsPrerelease is actually a boolean False which does not equal to the string false. I have just suddenly hit this issue and I do not understand how this happened. Seems like PackageManagement\Find-Package version does not match that of PowerShellGet\Find-Module In my case I have PackageManagement 1.4.7, but PowerShellGet 2.2.4.1

I do not understand why it started to happen suddenly. Some kind of an auto update.

MarkKharitonov commented 3 years ago

OK, I figured out the root cause. Another script loads the latest version of PowerShellGet which overshadows the old one. But this latest version is broken! Find-Module -AllVersions is broken and the fix is trivial - just do not compare with the 'false' string! Use !$psgetItemInfo.AdditionalMetadata.IsPrerelease instead or add it as an OR clause.

Is anyone looking at this one at all! This is frustrating.

Ben-Conrad commented 3 years ago

@FISHMANPET I was having the same issue with some modules I downloaded from the PSGallery using save-module and save-package. I can find-module in my local repository but only if I specify the -RequiredVersion. Using -AllowPrerelease shows me all the modules in the local repository. Thx!

sasmithCalpoly commented 2 years ago

I came across something like this just now. Out of curiosity, does it work if you specify add -AllowPrerelease to your search? It's not likely to be fixed, but I think I found a bug here:

https://github.com/PowerShell/PowerShellGetv2/blob/8c61ce7687de813438b0698c6eb461f610aa25ca/src/PowerShellGet/public/psgetfunctions/Find-Module.ps1#L158

Specifically this part $psgetItemInfo.AdditionalMetadata.IsPrerelease -eq 'false'. For a package that isn't prerelease, I don't think the AdditionalMetadata will have an IsPrerelease property, so $psgetItemInfo.AdditionalMetadata.IsPrerelease will return $null, so it essentially boils down to $null -eq 'false' which is itself false, so it won't execute the part of the code that will return the package. So it will accidentally filter out every package unless you specify -AllowPrerelease which will then also return PreRelease packages. Easy enough to fix, assuming my assumption that Find-Package won't set an IsPrerelease property when it's not prerelease. But I doubt it will happen since all the work is happening on v3.

I've tested and believe that on line 158, 'false' should be replaced with $false as is done in the Find-Script.ps1 for the same functionality.

https://github.com/PowerShell/PowerShellGetv2/blob/8c61ce7687de813438b0698c6eb461f610aa25ca/src/PowerShellGet/public/psgetfunctions/Find-Script.ps1#L166

In my local repository, my packages have IsPrerelease=False, where as the ones on PSGallery seem to have IsPrerelease=false

DennisL68 commented 1 year ago

And three years later...

alerickson commented 1 year ago

Hi @DennisL68, we're no longer working on this repository, see the read me. Please try PSResourceGet for continued improvements on what was previously PowerShellGet