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

Update PackageManagement #1239

Merged

Conversation

TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented Mar 23, 2020

I don't really want this at startup... but it's the best place for it, unfortunately.

This adds a feature to update the users version of PackageManagement if they have a bad version.

vscode-powershell settings PR: PowerShell/vscode-powershell#2651

@rjmholt rjmholt self-requested a review March 24, 2020 21:30
Copy link
Contributor

@rjmholt rjmholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is in the GetCommandHandler -- when's that fired? Is putting this installation option in the middle of that conflating two otherwise unrelated functionalities? Is there an earlier or separate point at which we could attempt installing a newer PackageManagement version?

Also will installing a newer PackageManagement version also necessitate an upgrade to PowerShellGet?

@TylerLeonhardt TylerLeonhardt force-pushed the update-packagemanagement branch from fda75a5 to 62f2763 Compare April 19, 2020 20:59
Comment on lines +103 to +106
new MessageActionItem
{
Title = "Not now"
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not adding a "don't tell me ever again" because:

  1. I don't know how to set a setting in the client from the server without adding yet another custom message
  2. I kinda wanna make it hard to find the setting to disable this because they really should update their PackageManagement...

Comment on lines 114 to 120
PSCommand psCommand = new PSCommand()
.AddCommand("Install-Module")
.AddParameter("Name", "PackageManagement")
.AddParameter("Force")
.AddParameter("MinimumVersion", s_desiredPackageManagementVersion)
.AddParameter("Scope", "CurrentUser")
.AddParameter("AllowClobber");
Copy link
Member Author

@TylerLeonhardt TylerLeonhardt Apr 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So apparently because PowerShell is silly.... psCommand.Commands[0].CommandText just prints out Install-Module.. which sucks. I've opened an issue but this feature is only for Windows PowerShell so... RIP.

Three options:

  • leave it like that...
  • add logic to PowerShellContextService to print params as well...
  • use ExecuteScriptStringAsync async instead and put a script in here instead of using PSCommand...

Thoughts @SeeminglyScience @rjmholt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this print?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd either use ExecuteScriptStringAsync or just bundle the module like we do with PSReadLine. Or just don't show it as input

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExecuteScriptStringAsync

I'm trying to avoid this one because apparently it doesn't play nice with ConstrainedLanguage mode? #1221 (comment)

and we wanna support that...

just bundle the module like we do with PSReadLine

We'd have to tack it to the front of the PSModulePath then :/

just don't show it as input

Unfortunately, this is probably the best option... although I wanted to show the user the command we're running so they could modify it if they have things like proxies or want to do AllUsers scope or whatever.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I mean where does the user see the printed output? I'm inferring from above that it looks like another command shown in the console. I think it's preferable to either not show it or fudge what's shown in some way if that's possible (like print a custom string or something)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I mean where does the user see the printed output?

Yeah in the PSIC. It just shows Install-Module. Nothing else.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an InputString to ExecutionOptions so that one can overwrite what gets put into History and sent to the Host.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so instead of that, I'm shelling out to powershell.exe... which would mean that as long as PackageManagement wasn't loaded in the session, the user won't have to restart their session.

@TylerLeonhardt TylerLeonhardt marked this pull request as ready for review April 21, 2020 02:37
@TylerLeonhardt TylerLeonhardt force-pushed the update-packagemanagement branch from 6fe3e48 to 81a3801 Compare April 21, 2020 22:22
@TylerLeonhardt TylerLeonhardt force-pushed the update-packagemanagement branch from 81a3801 to a9ced48 Compare April 21, 2020 22:25
@TylerLeonhardt
Copy link
Member Author

@SeeminglyScience @rjmholt this is a much smaller PR now.

@TylerLeonhardt
Copy link
Member Author

Codacy Here is an overview of what got changed by this pull request:

Issues
======
+ Solved 1
           

Complexity increasing per file
==============================
- src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetVersionHandler.cs  2
         

See the complete overview on Codacy

@TylerLeonhardt TylerLeonhardt merged commit f4c3f79 into PowerShell:master Apr 28, 2020
@TylerLeonhardt TylerLeonhardt deleted the update-packagemanagement branch April 28, 2020 17:15
@MSIH
Copy link

MSIH commented Jun 13, 2020

I am getting this error on some of my windows servers:

powershell.exe -NoLogo -NoProfile -Command 'Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber'

WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.

PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'PackageManagement'. 

Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

I was able to fix the problem by adding code to force to use TLS 1.2. Could you please update the command to use TLS 1.2?

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber

{
StringBuilder errors = new StringBuilder();
await _powerShellContextService.ExecuteScriptStringAsync(
"powershell.exe -NoLogo -NoProfile -Command 'Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber'",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This no longer works because the site requires TLS 1.2. I would recommend added code to force to use TLS 1.2

powershell.exe -NoLogo -NoProfile -Command '[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber

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

Successfully merging this pull request may close these issues.

4 participants