PowerShell / PowerShellGetv2

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

Save-Module fails with PackageManagement 1.1.7 when saving to a specific directory #210

Closed splatteredbits closed 6 years ago

splatteredbits commented 6 years ago

The Save-Module command fails using 1.1.7 of the PackageManagement module and saving the module to a specific path.

Expected Behavior

I expect to be able to save a module to a specific path.

Current Behavior

I get this error and no module is installed:

$ Save-Module -Name Pester -Path .output
Save-Package : A parameter cannot be found that matches parameter name 'AllowPrereleaseVersions'.
At C:\Build\Whiskey\Whiskey\PowerShellGet\PSModule.psm1:1836 char:52
+             $null = PackageManagement\Save-Package @PSBoundParameters
+                                                    ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Save-Package], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage

Possible Solution

The Save-Package command has five parameter sets, but only two of them have the AllowPrereleaseVersions. It doesn't look like any command that takes a name and path accept the AllowPrereleaseVersions switch. Call the correct parameter set with the correct parameters, or update the PackageManagement module to always allow the AllowPrereleaseVersions parameter set.

Steps to Reproduce (for bugs)

 $ Get-Module
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.0        chocolateyProfile                   {TabExpansion, Update-SessionEnvironment, refreshenv}
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script     0.2.0.0    PersistentHistory                   {Save-HistoryAll, Save-HistoryIncremental, Search-History, Test-HistoryToSave}
Script     0.7.1      posh-git                            {Add-PoshGitToProfile, Add-SshKey, Enable-GitColors, Get-AliasPattern...}

$ Import-Module .\PackageManagement
$ Import-Module .\PowerShellGet
$ Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.0        chocolateyProfile                   {TabExpansion, Update-SessionEnvironment, refreshenv}
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script     1.1.7.0    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider...}
Script     0.2.0.0    PersistentHistory                   {Save-HistoryAll, Save-HistoryIncremental, Search-History, Test-HistoryToSave}
Script     0.7.1      posh-git                            {Add-PoshGitToProfile, Add-SshKey, Enable-GitColors, Get-AliasPattern...}
Script     1.6.0      PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}

$ Save-Module -Name Pester -Path .output
Save-Package : A parameter cannot be found that matches parameter name 'AllowPrereleaseVersions'.
At C:\Build\Whiskey\Whiskey\PowerShellGet\PSModule.psm1:1836 char:52
+             $null = PackageManagement\Save-Package @PSBoundParameters
+                                                    ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Save-Package], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage

Context

We can't use Save-Module to download and install local copies of a module to a repository (similar to how NuGet packes and Node modules get installed into packages and node_modules directories inside a repository that uses it).

We can get past this issue by never passing AllowPrereleaseVersions to Save-Package, but then we lose the ability to install prerelease modules.

Your Environment

> $PSVersionTable

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

> Get-PackageProvider

Name                     Version          DynamicOptions
----                     -------          --------------
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
NuGet                    2.8.5.210        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscResource, RoleCapability, Command, Pub... Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent

> Get-PackageProvider -ListAvailable

Name                     Version          DynamicOptions
----                     -------          --------------
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
nuget                    2.8.5.208
NuGet                    2.8.5.210        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscResource, RoleCapability, Command, Pub... Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent
bmanikm commented 6 years ago

This is a duplicate of https://github.com/PowerShell/PowerShellGet/issues/208. Please take a look at my answer in https://github.com/PowerShell/PowerShellGet/issues/208#issuecomment-352130987 .