Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install-Module and Find-Module do not work when using MaximumVersion parameter and a PSRepository that requires credentials #485

Open
deadlydog opened this issue Dec 27, 2019 · 0 comments

Comments

@deadlydog
Copy link

deadlydog commented Dec 27, 2019

I originally reported this issue in the PowerShellGet repo, but after some investigation found that the module was simply calling PackageManagement\Install-Package and that is where the root of the issue is, which looks to be part of this repo.

Steps to reproduce

Install-Module -Name AzureArtifactsPowerShellModuleHelper -Scope CurrentUser -Force -MaximumVersion 2.999

Expected behavior

It downloads and installs the module without giving any output, warnings, or errors.

Actual behavior

On some machines, it gives the following error:

PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'AzureArtifactsPowerShellModuleHelper'. Try Get-PSRepository to see all available registered module repositories.
At C:\temp\PowerShellGet\public\psgetfunctions\Install-Module.ps1:163 char:34
+ ... talledPackages = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
   ception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Environment data

Windows Server 2012 and Windows 10.

PS C:\Users\Dan Schroeder> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14409.1018
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1018
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
PS C:\Users\Dan Schroeder> Get-Module -ListAvailable PowerShellGet,PackageManagement


    Directory: C:\Users\Dan Schroeder\Documents\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.4.5      PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Script     2.2.2      PowerShellGet                       {Find-Command, Find-DSCResource, Find-Module, Find-RoleCap...


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}
PS C:\Users\Dan Schroeder> Get-PackageProvider -ListAvailable

Name                     Version          DynamicOptions
----                     -------          --------------
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
NuGet                    2.8.5.208        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag...
PowerShellGet            2.2.2.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, ...
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, ...
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent

More Info

I can reliably reproduce the issue on a Windows Server 2012 computer (output above is from this server), but have also had some co-workers running Windows 10 report the same issue. The command works fine on my machine though, which is running Windows 10.

Here is a screenshot of running various commands on the Windows Server 2012 computer when using PowerShellGet 2.2 downloaded via the PowerShell Gallery:
Install-Module 2 2 2 broken by MaximumVersion

And here is a screenshot of the same commands running on the same Windows Server 2012 computer using the latest code on the master branch, commit sha d6b0808b84ba2aeb888b4f8fea2edd37a2bc8287 (has same output as above screenshot):
Install-Module master branch broken by MaximumVersion

In the above screenshots you should be able to ignore the warnings, as it's just complaining that it can't connect to our Azure Artifacts feed because it doesn't have credentials, but the module it's being told to install lives on the public PowerShell Gallery here.

Here is a screenshot of running the same Install-Module command on my local Windows 10 machine, and the command working as expected:
Install-Module works fine with MaximumVersion

It seems that using -MaximumVersion, regardless of what version number it's given (i.e. an existing version or a non-existent one), causes the command to fail. -MinimumVersion and -RequiredVersion seem to work properly; it's only -MaximumVersion that results in the module not being found and thus, not installed.

I also tried Find-Module and it seems to have the exact same problem. If any -MaximumVersion is specified it is unable to locate the module in the PowerShell gallery, but only on some computers. I assume that Install-Module is using Find-Module under the hood, but haven't looked at the code yet to verify.

The reason I'm wanting to use -MaximumParameter is to avoid having our PowerShell scripts automatically download new major versions of modules, as those are likely to include breaking changes (assuming the module follows semantic versioning), thus allowing our scripts to use new versions of modules (such as auto-updating to use 2.7 from 2.6), but preventing them from updating to new versions with breaking changes (such as auto-updating to 3.0). Until this bug is fixed, our workaround is to specify a -RequiredVersion instead, but that's not ideal.

Update

After a bit more investigation, it seems that after I remove my Azure Artifacts PSRepository (which requires credentials to access) from the Windows Server 2012 machine, then Find-Module and Install-Module work as expected. So the bug seems to be that when any of the registered PSRepositories requires credentials to access, then Find-Module with MaximumVersion doesn't work for any of the registered PSRepositories, even ones that do not require credentials.

Find-Module working after removing PSRepository

I'm not sure, but I know NuGet has a very similar bug that is perhaps related?

@deadlydog deadlydog changed the title Install-Module and Find-Module do not work when using MaximumVersion parameter Install-Module and Find-Module do not work when using MaximumVersion parameter and a PSRepository that requires credentials Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant