PowerShellGetv2 icon indicating copy to clipboard operation
PowerShellGetv2 copied to clipboard

Upgrade of the PSReadLine fails due that `The version '2.0.0' of module 'PSReadLine' is currently in use.`

Open it-praktyk opened this issue 4 years ago • 28 comments

Environment

PS version: 6.2.4
PSReadline version: 2.0.0-beta3
os: Linux <hostname> 5.3.0-40-generic PowerShell/PSReadLine#32~18.04.1-Ubuntu SMP Mon Feb 3 14:05:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
PS file version: 6.2.4.0
HostName: ConsoleHost
BufferWidth: 205
BufferHeight: 26

Exception report

Nope

Steps to reproduce

I try to update the PSReadLine module by the following instruction from the README

If you are using the version of PSReadLine that ships with PowerShell 6+ versions, you need to run: -noprofile -command "Install-Module PSReadLine -Force -SkipPublisherCheck -AllowPrerelease".

The return is

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

When I try to do that from PowerShell console

<user_name>% pwsh
PowerShell 6.2.4
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS <folder_name>> get-module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Script     2.0.0      PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler…}

PS <folder_name>> remove-module psreadline
PS <folder_name>> get-module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object…}

PS <folder_name>> Install-Module PSReadline -Force 
WARNING: The version '2.0.0' of module 'PSReadLine' is currently in use. Retry the operation after closing the applications.                                                                                 PS <folder_name>>

Expected behavior

The module will be installed from the PowerShell Gallery.

Actual behavior

As described in the 'Steps to reproduce' section.

it-praktyk avatar Feb 25 '20 22:02 it-praktyk

From the Upgrading section of README.md:

When running one of the suggested commands below, be sure to exit all instances of powershell.exe, pwsh.exe or pwsh, then run the suggested command from cmd.exe, powershell_ise.exe, or via the Win+R shortcut to make sure PSReadLine isn't loaded. ...

You need to close all powershell instances and then run <path-to-pwsh-executable> -noprofile -command "Install-Module PSReadLine -Force -SkipPublisherCheck -AllowPrerelease". Unloading the module doesn't unload the assembly from the PSReadLine module (by design in .NET), hence you need to close all instances.

daxian-dbw avatar Feb 27 '20 19:02 daxian-dbw

@daxian-dbw , please read the issue once again carefully.

PSReadLine is loaded (probably in background) by modules used to perform installation.

Please reopen my issue.

Thank you.

it-praktyk avatar Feb 27 '20 19:02 it-praktyk

In your repro, you are installing PSReadline within an interactive pwsh instance. For an interactive pwsh instance, PSReadLine is loaded at startup and its assemblies cannot be unloaded even if you remove the PSReadLine module. Therefore, Install-Module cannot remove those assemblies and thus believe the module is still in use.

Make sure you follow the upgrading instructions to install newer versions of PSReadLine.

daxian-dbw avatar Feb 27 '20 20:02 daxian-dbw

My repro confirms that unloaded PSReadLine is loaded under Install-Module and then blocks installation.

Maybe I was not strict enough with explaining. I tried proposed upgrade procedure too.

Please take a loog on the screenshot below.

Selection_005

it-praktyk avatar Feb 27 '20 20:02 it-praktyk

Thanks for clarifying your repro steps.

Now this looks like an issue with the Install-Module cmdlet, and I cannot repro locally with my Ubuntu machine. @alerickson @SydneyhSmith does this look familiar to you?

daxian-dbw avatar Feb 27 '20 20:02 daxian-dbw

Don't you need to run pwsh with the -noninteractive (sp?) switch for it to skip loading PSReadline (which it normally does as one of the first things in the session iirc).

vexx32 avatar Feb 27 '20 20:02 vexx32

@vexx32 When running -command without -noexit, PowerShell won't load PSReadLine, see the following example:

C:\>f:\pscore70.6\pwsh.exe -noprofile -command "Get-Module; 'no module loaded'"
no module loaded

daxian-dbw avatar Feb 27 '20 21:02 daxian-dbw

-NonInteractive and -NoExit doesn't work either.

Selection_007

it-praktyk avatar Feb 27 '20 21:02 it-praktyk

@it-praktyk @daxian-dbw that's not an issue I've seen before. As a work around, you can always use Save-Module and specify the module directory as the -path to install to.

alerickson avatar Feb 27 '20 21:02 alerickson

@alerickson This is on Linux. On Linux, Install-Module should be able to remove the assemblies from disk even if the assemblies are loaded into memory by another process. So I'm really confused about what might cause Install-Module to write out this warning.

Maybe this issue should be transferred to https://github.com/powershell/powershellget ?

daxian-dbw avatar Feb 27 '20 21:02 daxian-dbw

@daxian-dbw Yes, please transfer to PowerShellGet. It looks like PSGet tries to open a file to test whether the module is in use that's failing. @it-praktyk can you try running the following (with $FilePath being the path of the PSReadLine .psm1):

$fileInfo = New-Object System.IO.FileInfo $FilePath $fileStream = $fileInfo.Open( [System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None )

alerickson avatar Feb 27 '20 22:02 alerickson

@SteveL-MSFT Can you please help transfer this issue to the https://github.com/powershell/powershellget repository?

daxian-dbw avatar Feb 27 '20 23:02 daxian-dbw

If it is Install-Module issue we need to find and document a workaround in PSRadline repo if possible. Otherwise we get a lot of new issues opened in the repo :-)

iSazonov avatar Feb 28 '20 14:02 iSazonov

@iSazonov I'm pretty confident Save-Module -Path <specifiedmodulespath> would be a suitable workaround. @it-praktyk could you let us know if this does in fact work for you?

alerickson avatar Feb 28 '20 16:02 alerickson

I was able to save the PSReadLine module locally using the Save-Module command and Import it explicitly from the folder where

As a part of a documented workaround, I propose to add information about (one of them):

  • moving dowloaded module to the correct directory
  • updating a value of the PSModulePath variable
  • importing a module from explicitly provided directory.

it-praktyk avatar Feb 29 '20 09:02 it-praktyk

I've checked today - after upgrading to PSCore 7.0 - the issue still exists.

BTW, can you relabel the issue?

it-praktyk avatar Mar 05 '20 21:03 it-praktyk

This issue is really about Install-Module and should be moved to the PowerShellGet repository. Again, I cannot reproduce this on my Ubuntu ... 😦 @SteveL-MSFT Can you please help transfer this issue to PowerShellGet? @alerickson and I cannot do it ourselves.

daxian-dbw avatar Mar 05 '20 22:03 daxian-dbw

As for a workaround, we plan to publish version 2.0.1 with the same bits as in 2.0.0, so installing the latest module will be put in a 2.0.1 folder side-by-side with 2.0.0.

daxian-dbw avatar Mar 05 '20 22:03 daxian-dbw

@daxian-dbw - When moving from 1.2 to 2.0 - I changed the name of the DLL from Microsoft.PowerShell.PSReadLine.dll to Microsoft.PowerShell.PSReadLine2.dll to mitigate this issue somewhat.

I think the dll name could go back to the original name now since most systems have been using preview releases of 2.0.

lzybkr avatar Mar 06 '20 00:03 lzybkr

I temporarily moved the C:\Program Files\WindowsPowerShell\Modules\PSReadline Ran the Install-Module command and moved it back. This seemed to work.

mvanderlee avatar Mar 21 '20 20:03 mvanderlee

When i try to install the preview i get the following error: image

have no PowerShell instances open all closed and i am administrator on machine and using elevated privileges

aavdberg avatar Apr 07 '20 16:04 aavdberg

@aavdberg Another bizarre instance of the problem. And again, I cannot reproduce on my Windows machine ... (see the screenshot below)

@aavdberg Can you please open an issue in https://github.com/powershell/powershellget? Please describe the context of your environment, such as what previous version of PSReadLine were installed, at what location.

image

daxian-dbw avatar Apr 07 '20 17:04 daxian-dbw

Thank you @daxian-dbw made the following issue.

https://github.com/PowerShell/PowerShellGet/issues/108

aavdberg avatar Apr 07 '20 18:04 aavdberg

If I run this command from pwsh, I see that PSReadline is running in the below directory PS C:\Windows\System32> get-module psreadline|select-object -Property path Path

C:\program files\powershell\7\Modules\PSReadLine\PSReadLine.psm1

If I go to C:\program files\powershell\7\Modules and rename PSReadLine to PSReadLine.old

And then restart pwsh

And Run:

PS C:\Windows\System32> get-module psreadline|select-object -Property path Path

C:\Program Files\WindowsPowerShell\Modules\PSReadLine\2.0.1\PSReadLine.psm1

Maybe this is connected to the issue? A pyrrhic win of sorts in that PSReadLine 2.0.1 is loaded now.

kboguszewski avatar Apr 25 '20 20:04 kboguszewski

I wanted to share what finally worked for me. I did not understand that there were multiple versions of PSReadline installed for a myriad of profiles, each finding different versions.

Using each profile, run Get-Module -ListAvailable PSReadLine

I was able to see the details for all the found versions of PSReadline and their installation folders. I simply deleted all that I could find for each profile, and once done, then finally as administrator in powershell

Install-Module PSReadLine -AllowPrerelease -Force

I can't remember if VS Code terminal still did not see the PSReadline and I also needed to reinstall there, but everything is finally working well, and I only have one version of PSReadline installed

coinzdude avatar Nov 01 '21 15:11 coinzdude

What worked for me was this answer from: https://superuser.com/questions/1733481/how-to-update-psreadline-properly-in-powershell-7-2-5/1734993#1734993

  1. Close all PowerSlell, CMD, Windows Terminal, VS Code, etc. Might as well restart the PC.
  2. Win + R
  3. Paste: pwsh -noprofile -command "Install-Module PSReadLine -Force -SkipPublisherCheck -scope allusers"
  4. CONTROL + SHIFT + ENTER

JoanComasFdz avatar Dec 07 '22 12:12 JoanComasFdz

In case you have Powertoys installed make sure to close it as well.

JhossepPopayan avatar Feb 12 '23 14:02 JhossepPopayan

So how to properly upgrade PSRealine? Install module complains that

WARNING: Version '2.0.0' of module 'PSReadline' is already installed at 'C:\Program Files\WindowsPowerShell\Modules\PSReadline\2.0.0'. To install version '2.2.6', run Install-Module and add the -Force parameter, this command will install version '2.2.6' in side-by-side with version '2.0.0'

So how to not install it side-by-side? Is this not supported? I can't remove 2.0.0 via Uninstall-Module because it wasn't installed that way (I think it's the one shipped with win 1 by default). Is the only option to remove psreadline module is to go and manually delete the files and hope nothing breaks?

danilaml avatar Aug 11 '23 18:08 danilaml