PSResourceGet icon indicating copy to clipboard operation
PSResourceGet copied to clipboard

Uninstall-PSResource throws dependency check fail when uninstalling old versions

Open ThomasNieto opened this issue 3 years ago • 0 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest released version
  • [X] Search the existing issues.

Steps to reproduce

I am trying to uninstall old module versions and its throwing a dependency check error even though the latest version 1.20.0 will be not be uninstalled only 1.19.1 and 1.18.3.

C:\> Get-PSResource PSScriptAnalyzer, PSCodeHealth

Name             Version  Prerelease Repository Description
----             -------  ---------- ---------- -----------
PSScriptAnalyzer 1.20.0.0            PSGallery  PSScriptAnalyzer provides script analysis and checks for potential code defects in the scripts by applying a group of built-in or customized rules on the scrip…
PSScriptAnalyzer 1.19.1              PSGallery  PSScriptAnalyzer provides script analysis and checks for potential code defects in the scripts by applying a group of built-in or customized rules on the scrip…
PSScriptAnalyzer 1.18.3              PSGallery  PSScriptAnalyzer provides script analysis and checks for potential code defects in the scripts by applying a group of built-in or customized rules on the scrip…
PSCodeHealth     0.2.26.0            PSGallery  This module allows you to measure the quality and maintainability of your PowerShell code, based on a variety of metrics.

C:\> Get-PSResource PSCodeHealth | select -ExpandProperty Dependencies

Name             VersionRange
----             ------------
Pester           (, )
PSScriptAnalyzer (, )

C:\> Get-PSResource PSScriptAnalyzer -Version '(,1.20.0)'

Name             Version Prerelease Repository Description
----             ------- ---------- ---------- -----------
PSScriptAnalyzer 1.19.1             PSGallery  PSScriptAnalyzer provides script analysis and checks for potential code defects in the scripts by applying a group of built-in or customized rules on the script…
PSScriptAnalyzer 1.18.3             PSGallery  PSScriptAnalyzer provides script analysis and checks for potential code defects in the scripts by applying a group of built-in or customized rules on the script…

C:\> Uninstall-PSResource PSScriptAnalyzer -Version '(,1.20.0)'
Uninstall-PSResource: Cannot uninstall 'PSScriptAnalyzer'. The following package(s) take a dependency on this package: PSCodeHealth. If you would still like to uninstall, rerun the command with -SkipDependencyCheck
Uninstall-PSResource: Cannot uninstall 'PSScriptAnalyzer'. The following package(s) take a dependency on this package: PSCodeHealth. If you would still like to uninstall, rerun the command with -SkipDependencyCheck

Expected behavior

Uninstall successfully.

Actual behavior

C:\> Uninstall-PSResource PSScriptAnalyzer -Version '(,1.20.0)'
Uninstall-PSResource: Cannot uninstall 'PSScriptAnalyzer'. The following package(s) take a dependency on this package: PSCodeHealth. If you would still like to uninstall, rerun the command with -SkipDependencyCheck
Uninstall-PSResource: Cannot uninstall 'PSScriptAnalyzer'. The following package(s) take a dependency on this package: PSCodeHealth. If you would still like to uninstall, rerun the command with -SkipDependencyCheck

Error details

C:\> Get-Error

Exception             :
    Type        : System.Management.Automation.PSInvalidOperationException
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Cannot uninstall 'PSScriptAnalyzer'. The following package(s) take a dependency on this package: PSCodeHealth. If you would still like to uninstall, rerun the command with
-SkipDependencyCheck
            HResult : -2146233087
        CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : InvalidOperation
    Message     : Cannot uninstall 'PSScriptAnalyzer'. The following package(s) take a dependency on this package: PSCodeHealth. If you would still like to uninstall, rerun the command with
-SkipDependencyCheck
    HResult     : -2146233079
CategoryInfo          : InvalidOperation: (:) [Uninstall-PSResource], PSInvalidOperationException
FullyQualifiedErrorId : UninstallPSResourcePackageIsaDependency,Microsoft.PowerShell.PowerShellGet.Cmdlets.UninstallPSResource
InvocationInfo        :
    MyCommand        : Uninstall-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 34
    Line             : Uninstall-PSResource PSScriptAnalyzer -Version '(,1.20.0)'
    PositionMessage  : At line:1 char:1
                       + Uninstall-PSResource PSScriptAnalyzer -Version '(,1.20.0)'
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Uninstall-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

C:\> Get-Module PowerShellGet

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     3.0.12     beta       PowerShellGet                       {Find-PSResource, Get-PSResource, Get-PSResourceRepository, Install-PSResource…}

C:\> $PSVersionTable

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

Visuals

No response

ThomasNieto avatar May 30 '22 02:05 ThomasNieto