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

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

Open
it-praktyk opened this issue Feb 25, 2020 · 28 comments

Comments

@it-praktyk
Copy link

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.

@daxian-dbw
Copy link
Member

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.

@it-praktyk
Copy link
Author

@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.

@daxian-dbw
Copy link
Member

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.

@it-praktyk
Copy link
Author

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

@daxian-dbw
Copy link
Member

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 daxian-dbw reopened this Feb 27, 2020
@vexx32
Copy link

vexx32 commented Feb 27, 2020

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).

@daxian-dbw
Copy link
Member

@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

@it-praktyk
Copy link
Author

-NonInteractive and -NoExit doesn't work either.

Selection_007

@alerickson
Copy link
Member

@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.

@daxian-dbw
Copy link
Member

daxian-dbw commented Feb 27, 2020

@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 ?

@alerickson
Copy link
Member

@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 )

@daxian-dbw
Copy link
Member

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

@iSazonov
Copy link

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 :-)

@alerickson
Copy link
Member

alerickson commented Feb 28, 2020

@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?

@it-praktyk
Copy link
Author

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
Copy link
Author

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

BTW, can you relabel the issue?

@daxian-dbw
Copy link
Member

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
Copy link
Member

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.

@lzybkr
Copy link
Member

lzybkr commented Mar 6, 2020

@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.

@mvanderlee
Copy link

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

@aavdberg
Copy link

aavdberg commented Apr 7, 2020

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

@daxian-dbw
Copy link
Member

@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

@aavdberg
Copy link

aavdberg commented Apr 7, 2020

Thank you @daxian-dbw made the following issue.

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

@kboguszewski
Copy link

kboguszewski commented Apr 25, 2020

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.

@daxian-dbw daxian-dbw transferred this issue from PowerShell/PSReadLine Mar 10, 2021
@coinzdude
Copy link

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

@JoanComasFdz
Copy link

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

@JhossepPopayan
Copy link

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

@danilaml
Copy link

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?

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