OneGet / oneget

PackageManagement (aka OneGet) is a package manager for Windows
MIT License
2.38k stars 189 forks source link

v7.0.0-preview.1 - Uninstall-Package fails uninstalling modules/packages #461

Closed peppekerstens closed 5 years ago

peppekerstens commented 5 years ago

See https://github.com/PowerShell/PowerShell/issues/9876 . Got redirected to this repo.

$PSversionTable

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.1
PSEdition                      Core
GitCommitId                    7.0.0-preview.1
OS                             Microsoft Windows 10.0.18356
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
True

get-package buildhelpers

Name                           Version          Source                           ProviderName
----                           -------          ------                           ------------
BuildHelpers                   2.0.9            https://www.powershellgallery.c… PowerShellGet

$package = get-package buildhelpers
([xml]$package.SwidTagText).SoftwareIdentity.Meta.InstalledLocation
C:\Users\...\...\...\PowerShell\Modules\BuildHelpers\2.0.9

uninstall-package buildhelpers
uninstall-package : Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
At line:1 char:1
+ uninstall-package buildhelpers
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (Microsoft.PowerShel…ts.UninstallPackage:UninstallPackage) [Uninstall-Package], Exception
+ FullyQualifiedErrorId : System.FormatException,Microsoft.PowerShell.Commands.RemoveItemCommand,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage
peppekerstens commented 5 years ago
 $psversiontable

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

$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
True

uninstall-package buildhelpers

Name                           Version          Source           Summary
----                           -------          ------           -------
BuildHelpers                   2.0.9            https://www.p... Helper functions for PowerShell CI/CD scenarios.
peppekerstens commented 5 years ago
$PSversionTable

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.1
PSEdition                      Core
GitCommitId                    7.0.0-preview.1
OS                             Microsoft Windows 10.0.18356
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

get-module packagemanagement

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.4        PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Packa…
SydneyhSmith commented 5 years ago

@peppekerstens thanks for reporting this issue, I am having some difficulty reproducing it--could you also provide the verbose output of the uninstall i.e. Uninstall-Package BuildHelpers -Verbose -Debug Thanks!

peppekerstens commented 5 years ago

Just installed the update for PowerShell 6 (to 6.2.1). Due to PS restarts i cannot show all actual output anymore.

So (traceback):

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

Then:

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.1
PSEdition                      Core
GitCommitId                    6.2.1
OS                             Microsoft Windows 10.0.18356
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS 6.2.1. comes 'pre-installed' with packagemanagement 1.3.2. So i decided to update it to 1.4.0 for fair reference with PS7:

install-module packagemanagement -requiredversion 1.4.0 -force

After restarting PowerShell 6:

PowerShell 6.2.1
Copyright (c) Microsoft Corporation. All rights reserved.
                                                                                                                        https://aka.ms/pscore6-docs                                                                                             Type 'help' to get help.                                                                                                                                                                                                                        Loading personal and system profiles took 878ms.                                                                        C:\Users\peppe> get-module packagemanagement
C:\Users\peppe> get-module packagemanagement
C:\Users\peppe> get-package packagemanagement
get-package : No package found for 'packagemanagement'.
At line:1 char:1
+ get-package packagemanagement
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Microsoft.PowerShel\u2026.Cmdlets.GetPackage:GetPackage) [Get-Package], Exception
+ FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage

C:\Users\peppe> install-module packagemanagement -requiredversion 1.4.0 -force
PackageManagement\Install-Package : Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
At C:\program files\powershell\6\Modules\PowerShellGet\PSModule.psm1:9508 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (Microsoft.PowerShel\u2026lets.InstallPackage:InstallPackage) [Install-Package], Exception
+ FullyQualifiedErrorId : System.FormatException,Microsoft.PowerShell.Commands.RemoveItemCommand,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

FUBAR now :(

peppekerstens commented 5 years ago

@SydneyhSmith after above action in PS6, first confirmed if issue in PS7 remains (they seem to intermix on the modules/packages):

C:\Temp> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.1
PSEdition                      Core
GitCommitId                    7.0.0-preview.1
OS                             Microsoft Windows 10.0.18356
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

C:\Temp> Uninstall-Package BuildHelpers
Uninstall-Package : Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
At line:1 char:1
+ Uninstall-Package BuildHelpers
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (Microsoft.PowerShel…ts.UninstallPackage:UninstallPackage) [Uninstall-Package], Exception
+ FullyQualifiedErrorId : System.FormatException,Microsoft.PowerShell.Commands.RemoveItemCommand,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage

C:\Temp> Uninstall-Package BuildHelpers -Verbose -Debug
DEBUG: 00:00:00.0000004 Calling New() : MethodName = 'GetDynamicOptions'
DEBUG: 00:00:00.0000358 Debug: True
DEBUG: 00:00:00.0000580 Verbose: True
DEBUG: 00:00:00.0000792 Name: BuildHelpers
DEBUG: 00:00:00.0010465 INVOKING PowerShell Fn Get-DynamicOptions with args Provider that has length 1
DEBUG: 00:00:00.0017627 In PowerShellGet Provider - 'Get-DynamicOptions'.
DEBUG: 00:00:00.0032725 Done calling powershell «Get-DynamicOptions» «PSModule»
DEBUG: 00:00:00.0112191 Calling New() : MethodName = 'GetDynamicOptions'
DEBUG: 00:00:00.0112514 Debug: True
DEBUG: 00:00:00.0112736 Verbose: True
DEBUG: 00:00:00.0112942 Name: BuildHelpers
DEBUG: 00:00:00.0121679 INVOKING PowerShell Fn Get-DynamicOptions with args Install that has length 1
DEBUG: 00:00:00.0130423 In PowerShellGet Provider - 'Get-DynamicOptions'.
DEBUG: 00:00:00.0160623 Done calling powershell «Get-DynamicOptions» «PSModule»
DEBUG: 00:00:00.0532753 Calling 'NuGet'::'GetInstalledPackages' - name='BuildHelpers', requiredVersion='',minimumVersion='', maximumVersion='''.
DEBUG: 00:00:00.0535960 AllUserDefaultInstallLocation: C:\Program Files\PackageManagement\NuGet\Packages
DEBUG: 00:00:00.0543940 Calling New() : MethodName = 'GetInstalledPackages'
DEBUG: 00:00:00.0545757 Debug: True
DEBUG: 00:00:00.0545757 CurrentUserDefaultInstallLocation: C:\Users\peppe\AppData\Local\PackageManagement\NuGet\Packages
DEBUG: 00:00:00.0546211 Verbose: True
DEBUG: 00:00:00.0546632 Name: BuildHelpers
DEBUG: 00:00:00.0569407 INVOKING PowerShell Fn Get-InstalledPackage with args BuildHelpers, , ,  that has length 4
DEBUG: 00:00:00.0583216 In PowerShellGet Provider - 'Get-InstalledPackage'.
DEBUG: 00:00:00.0585170 OPTION: Debug => True
DEBUG: 00:00:00.0602491 OPTION: Verbose => True
DEBUG: 00:00:00.0604478 OPTION: Name => BuildHelpers
DEBUG: 00:00:00.4956726 Done calling powershell «Get-InstalledPackage» «PSModule»
DEBUG: 00:00:00.4994053 Uninstalling package BuildHelpers with provider PowerShellGet

Confirm
Are you sure you want to perform this action?
Performing the operation "Uninstall Package." on target "Package 'BuildHelpers' with version '2.0.9'.".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
DEBUG: 00:00:16.5014425 Calling New() : MethodName = 'UninstallPackage'
DEBUG: 00:00:16.5014722 Debug: True
DEBUG: 00:00:16.5014901 Verbose: True
DEBUG: 00:00:16.5015057 Name: BuildHelpers
DEBUG: 00:00:16.5022162 INVOKING PowerShell Fn Uninstall-Package with args NuGet|BuildHelpers|2.0.9|https://www.powershellgallery.com/api/v2/|Module that has length 1
DEBUG: 00:00:16.5028220 In PowerShellGet Provider - 'Uninstall-Package'.
DEBUG: 00:00:16.5029284 The FastPackageReference is 'NuGet|BuildHelpers|2.0.9|https://www.powershellgallery.com/api/v2/|Module'.
DEBUG: 00:00:16.5033990 OPTION: Debug => True
DEBUG: 00:00:16.5036093 OPTION: Verbose => True
DEBUG: 00:00:16.5038139 OPTION: Name => BuildHelpers
VERBOSE: Successfully uninstalled the module 'BuildHelpers' from module base 'C:\Users\peppe\OneDrive\Documenten\PowerShell\Modules\BuildHelpers\2.0.9'.
Uninstall-Package : Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
At line:1 char:1
+ Uninstall-Package BuildHelpers -Verbose -Debug
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (Microsoft.PowerShel…ts.UninstallPackage:UninstallPackage) [Uninstall-Package], Exception
+ FullyQualifiedErrorId : System.FormatException,Microsoft.PowerShell.Commands.RemoveItemCommand,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage

After this, I checked the directory:

C:\Temp> Get-ChildItem -Path 'C:\Users\peppe\OneDrive\Documenten\PowerShell\Modules\BuildHelpers\2.0.9'

    Directory: C:\Users\peppe\OneDrive\Documenten\PowerShell\Modules\BuildHelpers\2.0.9

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
la---            6/8/2019  9:14 AM                en-US ->
la---            6/8/2019  9:14 AM                Private ->
la---            6/8/2019  9:14 AM                Public ->
la---            6/8/2019  9:14 AM                Scripts ->
la---            6/1/2019  8:03 PM           4274 BuildHelpers.psd1 ->
la---            6/1/2019  8:02 PM           2408 BuildHelpers.psm1 ->

So the module remains...

peppekerstens commented 5 years ago

Fiddled around with PS6.

Got default version for PS6 back for PackageManagement. What happend; it seems that my forced install of PackageManagement resulted in an install in my personal PSModulePath instead of the system module path(??).

Force removed the PackageManagement 1.4 version in personal PSModulePath. Now it is back to default PS6 version:

C:\Program Files\PowerShell\6> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.1
PSEdition                      Core
GitCommitId                    6.2.1
OS                             Microsoft Windows 10.0.18356
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Get-Module PackageManagement

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.3.2      PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Packag…

This however does not help: it does not detect the other packages/module in my personal PSModulePath anymore, these are present:

C:\Users\peppe> Get-ChildItem -Path 'C:\Users\peppe\OneDrive\Documenten\PowerShell\Modules'

    Directory: C:\Users\peppe\OneDrive\Documenten\PowerShell\Modules

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
da---l          6/8/2019  9:14 AM                BuildHelpers
da---l         5/30/2019  9:45 AM                GenericFunctions
da---l         6/12/2019  9:07 AM                VstsHelper

Strange; these have been installed by/with PS6 and is the same directory where i force removed the PackageManagement 1.40 version in previous post...

SydneyhSmith commented 5 years ago

Thanks for looking into this @peppekerstens after some review I am thinking that this may be the same issue as https://github.com/PowerShell/PowerShell/issues/9798 in which case the best thing to do is try these instructions: https://github.com/PowerShell/PowerShell/issues/9798#issuecomment-502147416

peppekerstens commented 5 years ago

Not quite :)

After some testing on a vanilla W2019 machine (issue #462), this is the situation:

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17763.503
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.503
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                    3.0.0.1          Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag...
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, ...
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent
$PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.1
PSEdition                      Core
GitCommitId                    6.2.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

get-packageprovider

Name                     Version          DynamicOptions
----                     -------          --------------
NuGet                    3.0.0.1          Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, …
PowerShellGet            2.1.3.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, In…

Installed 7 preview:

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.1
PSEdition                      Core
GitCommitId                    7.0.0-preview.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

Get-PackageProvider

Name                     Version          DynamicOptions
----                     -------          --------------
NuGet                    3.0.0.1          Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, …
PowerShellGet            2.1.4.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, In…

Let's first check my reported issue:

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.1
PSEdition                      Core
GitCommitId                    7.0.0-preview.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

#installed during testing for issue #462, under PS6:
get-package BuildHelpers

Name                           Version          Source                           ProviderName
----                           -------          ------                           ------------
BuildHelpers                   2.0.9            https://www.powershellgallery.c… PowerShellGet

$package = get-package buildhelpers
PS C:\Users\pkadmin> ([xml]$package.SwidTagText).SoftwareIdentity.Meta.InstalledLocation
C:\Users\pkadmin\Documents\PowerShell\Modules\BuildHelpers\2.0.9

Uninstall-Package buildhelpers

Name                           Version          Source           Summary
----                           -------          ------           -------
BuildHelpers                   2.0.9            https://www.pow… Helper functions for PowerShell CI/CD scenarios.

So I guess i should look into/re-install my machine because i cannot confirm on this machine either.