OneGet / oneget

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

Remove Circular dependency between PackageManagement and PowerShellGet, inability to uninstall modules #344

Open jzabroski opened 6 years ago

jzabroski commented 6 years ago

Wow, check this out. It's possible I'm doing things wrong but wow is this complicated.

PS C:\WINDOWS\system32> install-module -name PowerShellGet -Force
WARNING: The version '1.1.7.0' of module 'PackageManagement' is currently in use. Retry the operation after closing the
 applications.
PS C:\WINDOWS\system32> install-module -name PackageManagement -AllowPrerelease

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): a
WARNING: Version '1.1.7.0' of module 'PackageManagement' is already installed at 'C:\Program
Files\WindowsPowerShell\Modules\PackageManagement\1.1.7.0'. To install version '1.2.0-preview', run Install-Module and
add the -Force parameter, this command will install version '1.2.0-preview' in side-by-side with version '1.1.7.0'.
PS C:\WINDOWS\system32> install-module -name PackageManagement -AllowPrerelease -Force
PS C:\WINDOWS\system32> install-module -name PowerShellGet -Force
WARNING: The version '1.1.7.0' of module 'PackageManagement' is currently in use. Retry the operation after closing the
 applications.

PS C:\WINDOWS\system32> get-module PackageManagement

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.1.7.0    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...

PS C:\WINDOWS\system32> get-module PackageManagement -All

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.1.7.0    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...

PS C:\WINDOWS\system32> get-module PackageManagement -ListAvailable

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.2.0      PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Script     1.1.7.0    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...

PS C:\WINDOWS\system32> import-module PackageManagement -Version 1.2.0
PS C:\WINDOWS\system32> get-module PackageManagement

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.1.7.0    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...
Script     1.2.0      PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...

I can't seem to remove 1.1.7.0 and I have no idea when I'm running Find-Package if it actually is using 1.2.0 or 1.1.7.0:

PS C:\WINDOWS\system32> Find-Package -Name NLog -Source nuget.org -Verbose
VERBOSE: Using the provider 'NuGet' for searching packages.
VERBOSE: Searching repository 'https://api.nuget.org/v3/index.json/FindPackagesById()?id='NLog'' for ''.
Find-Package : No match was found for the specified search criteria and package name 'NLog'. Try Get-PackageSource to
see all available registered package sources.
At line:1 char:1
+ Find-Package -Name NLog -Source nuget.org -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exceptio
   n
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage

Think I'm done having fun?

Now, what would be logical at this point, is to try uninstalling 1.1.7.0 using something named Uninstall-Module... but nope... that's not possible. The fun has to continue.

PS C:\WINDOWS\system32> Uninstall-Module  PackageManagement
PackageManagement\Uninstall-Package : The module 'PackageManagement' of version '1.2.0-preview' in module base folder
'C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.2.0' cannot be uninstalled, because one or more other
modules 'PowerShellGet' are dependent on this module. Uninstall the modules that depend on this module before
uninstalling module 'PackageManagement'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.6.0\PSModule.psm1:2459 char:21
+ ...        $null = PackageManagement\Uninstall-Package @PSBoundParameters
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Packag
   e], Exception
    + FullyQualifiedErrorId : UnableToUninstallAsOtherModulesNeedThisModule,Uninstall-Package,Microsoft.PowerShell.Pac
   kageManagement.Cmdlets.UninstallPackage

PS C:\WINDOWS\system32> get-module PackageManagement

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.1.7.0    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...
Script     1.2.0      PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...

On top of this, the documentation online constantly warns users about confusing the PackageManagement cmdlets with the Visual Studio NuGet Package Manager cmdlets, but there is no explanation for what to call "Visual Studio NuGet Package Manager cmdlets" other than "Visual Studio NuGet Package Manager cmdlets" (mouthful), and 90% of all searches for Find-Package end up putting you back on to "Visual Studio NuGet Package Manager cmdlets" blog posts, documentation, etc.

dsgon commented 4 years ago

Hi.

I have the same issue when I try to install PowerShellGet

Install-Module -Name PowerShellGet -Repository PSGallery -Force -SkipPublisherCheck

WARNING: The version '1.4.7' of module 'PackageManagement' is currently in use. Retry the operation after closing the applications.

So I decided to uninstall the PackageManagement and I get this message error:

Uninstall-Package: C:\Users\<my_user>\Documents\PowerShell\Modules\PowerShellGet\2.2.4.1\PSModule.psm1:12731
 Line |
12731 |  …        $null = PackageManagement\Uninstall-Package @PSBoundParameters
      |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      | No match was found for the specified search criteria and module names 'PackageManagement'.

But I have this module!!!

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     1.4.7                 PackageManagement                   {Find-Package, Find-PackageProvider, Get-…

And it's not all, because if I look into the PackageManagement folder I see this:

 Directory: C:\Program Files\WindowsPowerShell\Modules\PackageManagement

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----           19/3/2019    08:49                1.0.0.1

1.0.0.1 ??? But the version installed is 1.4.7.

I don't know how to fix this issue.

dsgon commented 4 years ago

Hi everyone.

I found a solution to this 'issue'.

The first mistake was that Powershell core is NO the same that Powershell, in my case I'm using the new windows Terminal, so with this in mind, I decided to uninstall azure module in both Powershell.

After the uninstall process, I Installed the Azure module on PowerShell core and Powershell by separated (I think that was unnecessary) and then I import in Powershell core Az, Az.Account and Az.Resources modules and this worked for me.

I hope that this can help you

utami1511 commented 3 years ago

@dsgon can you please show the commands that you ran to unistall and install to fix the issue?

graememeyer commented 3 years ago

This is a dumb as hell issue to even have in the first place. My solution was:

This operation now succeeds. Finally:

diligent176 commented 3 years ago

I'm having the same issue

B4Art commented 3 years ago

My thingking: There is a difference between machine(system) and user Modules. The usermodules have preference above the system modules. You are able to install modules where you want theme to be via -scope. You can install theme in both locations at the same time. What happens if you install different versions for user and system? How do you replace the newest version? How do you replace the running version? How do you know which (system v.s. user) module is running? If I uninstall 1 module which exist in both location and is a fundamental mdule like packagemanagement... I have not investigated these yet, but hey, lets share these questions and then come with a solution.

graememeyer commented 3 years ago

Hmm. Surely this has been solved by other modules that update?

It's certainly possible to define the install scope: https://docs.microsoft.com/en-us/powershell/module/powershellget/install-module?view=powershell-5.1#parameters:~:text=Specifies%20the%20installation%20scope%20of%20the%20module

And you can programatically determine what's loaded in the current session with Get-Module

PS C:\Users\UserName> (Get-Module).path
C:\ProgramData\chocolatey\helpers\chocolateyProfile.psm1
C:\windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1
C:\windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1
C:\Program Files\WindowsPowerShell\Modules\PSReadline\2.0.0\PSReadLine.psm1
B4Art commented 3 years ago

Hmm. Surely this has been solved by other modules that update?

It's certainly possible to define the install scope: https://docs.microsoft.com/en-us/powershell/module/powershellget/install-module?view=powershell-5.1#parameters:~:text=Specifies%20the%20installation%20scope%20of%20the%20module

And you can programatically determine what's loaded in the current session with Get-Module

PS C:\Users\UserName> (Get-Module).path
C:\ProgramData\chocolatey\helpers\chocolateyProfile.psm1
C:\windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1
C:\windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1
C:\Program Files\WindowsPowerShell\Modules\PSReadline\2.0.0\PSReadLine.psm1

Small change which will also show the usermodules loaded:

(Get-Module -All).path

Or showing only userscope:

((Get-Module -All).Path).where({$_ -notin (Get-Module).Path})