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

Dependencies not checked correctly when running Uninstall-Module #49

Open
3 tasks done
donlassini opened this issue Sep 28, 2023 · 0 comments
Open
3 tasks done

Comments

@donlassini
Copy link

donlassini commented Sep 28, 2023

Prerequisites

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

Steps to reproduce

I have a module that is dependent on version 5.4.0 of the Microsoft Teams module.
Uninstalling version 5.3.0 of the Teams module fails, giving a dependency error.
I can uninstall by using the -Force parameter; however that should not be necessary since the older Teams module is outside the dependency scope.

Some further details:

PS> Get-Module MyModule -ListAvailable

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name      PSEdition ExportedCommands
---------- -------    ---------- ----      --------- ----------------
Script     1.0.0.1               MyModule  Core,Desk {Get-MyFunction, Set-MyFunction, …}

PS> (Get-Module MyModule -ListAvailable).RequiredModules

ModuleType Version PreRelease Name                                         ExportedCommands
---------- ------- ---------- ----                                         ----------------
Script     5.4.0              MicrosoftTeams
    
PS> Get-Module MicrosoftTeams -ListAvailable

    Directory: C:\Program Files\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     5.4.0                 MicrosoftTeams                      Core,Desk {Add-TeamChannelUser, Add-TeamUser, Connect-MicrosoftTeams, Disconnect-MicrosoftTeams…}
Script     5.3.0                 MicrosoftTeams                      Core,Desk {Add-TeamChannelUser, Add-TeamUser, Connect-MicrosoftTeams, Disconnect-MicrosoftTeams…}

MyModule.psd1 has the following section:

....
RequiredModules   = @(
	@{
		ModuleName    = "MicrosoftTeams";
		ModuleVersion = "5.4.0";
		Guid          = "d910df43-3ca6-4c9c-a2e3-e9f45a8e2ad9"
	}
)

Expected behavior

I would expect the Teams module to be uninstalled correctly.
PS> Uninstall-Module -Name MicrosoftTeams -RequiredVersion 5.3.0
PS>

Actual behavior

PS> Uninstall-Module -Name MicrosoftTeams -RequiredVersion 5.3.0
Uninstall-Package: The module 'MicrosoftTeams' of version '5.3.0' in module base folder 'C:\Program Files\PowerShell\Modules\MicrosoftTeams\5.3.0' cannot be uninstalled, because one or more other modules
'MyModule' are dependent on this module. Uninstall the modules that depend on this module before uninstalling module 'MicrosoftTeams'.

Error details

PS> Get-Error

Exception             :
    Type    : System.Exception
    Message : The module 'MicrosoftTeams' of version '5.3.0' in module base folder 'C:\Program Files\PowerShell\Modules\MicrosoftTeams\5.3.0' cannot be uninstalled, because one or more other modules
 'MyModule' are dependent on this module. Uninstall the modules that depend on this module before uninstalling module 'MicrosoftTeams'.
    HResult : -2146233088
TargetObject          : Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage
CategoryInfo          : InvalidOperation: (Microsoft.PowerShel…ts.UninstallPackage:UninstallPackage) [Uninstall-Package], Exception
FullyQualifiedErrorId : UnableToUninstallAsOtherModulesNeedThisModule,Uninstall-Package,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage
InvocationInfo        :
    MyCommand        : Uninstall-Package
    ScriptLineNumber : 12733
    OffsetInLine     : 21
    HistoryId        : 38
    ScriptName       : C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1
    Line             : $null = PackageManagement\Uninstall-Package @PSBoundParameters

    PositionMessage  : At C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1:12733 char:21
                       + …        $null = PackageManagement\Uninstall-Package @PSBoundParameters
                       +                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\program files\powershell\7\Modules\PowerShellGet
    PSCommandPath    : C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1
    InvocationName   : PackageManagement\Uninstall-Package
    CommandOrigin    : Internal
ScriptStackTrace      : at Uninstall-Module<Process>, C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1: line 12733
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

PS> $PSVersionTable

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

Version

2.2.5

Visuals

No response

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