Skip to content

Remove PackageManagement module update prompt #1735

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ namespace Microsoft.PowerShell.EditorServices.Handlers
{
internal class GetVersionHandler : IGetVersionHandler
{
private static readonly Version s_desiredPackageManagementVersion = new Version(1, 4, 6);

private readonly ILogger<GetVersionHandler> _logger;
private IRunspaceContext _runspaceContext;
private readonly IInternalPowerShellExecutionService _executionService;
Expand Down Expand Up @@ -58,11 +56,6 @@ public async Task<PowerShellVersion> Handle(GetVersionParams request, Cancellati
}
}

if (VersionUtils.IsPS5 && _configurationService.CurrentSettings.PromptToUpdatePackageManagement)
{
await CheckPackageManagement().ConfigureAwait(false);
}

return new PowerShellVersion
{
Version = VersionUtils.PSVersionString,
Expand All @@ -78,80 +71,5 @@ private enum PowerShellProcessArchitecture
X86,
X64
}

private async Task CheckPackageManagement()
{
PSCommand getModule = new PSCommand().AddCommand("Get-Module").AddParameter("ListAvailable").AddParameter("Name", "PackageManagement");
foreach (PSModuleInfo module in await _executionService.ExecutePSCommandAsync<PSModuleInfo>(getModule, CancellationToken.None).ConfigureAwait(false))
{
// The user has a good enough version of PackageManagement
if (module.Version >= s_desiredPackageManagementVersion)
{
break;
}

_logger.LogDebug("Old version of PackageManagement detected.");

if (_runspaceContext.CurrentRunspace.Runspace.SessionStateProxy.LanguageMode != PSLanguageMode.FullLanguage)
{
_languageServer.Window.ShowWarning("You have an older version of PackageManagement known to cause issues with the PowerShell extension. Please run the following command in a new Windows PowerShell session and then restart the PowerShell extension: `Install-Module PackageManagement -Force -AllowClobber -MinimumVersion 1.4.6`");
return;
}

var takeActionText = "Yes";
MessageActionItem messageAction = await _languageServer.Window.ShowMessageRequest(new ShowMessageRequestParams
{
Message = "You have an older version of PackageManagement known to cause issues with the PowerShell extension. Would you like to update PackageManagement (You will need to restart the PowerShell extension after)?",
Type = MessageType.Warning,
Actions = new[]
{
new MessageActionItem
{
Title = takeActionText
},
new MessageActionItem
{
Title = "Not now"
}
}
})
.ConfigureAwait(false);

// If the user chose "Not now" ignore it for the rest of the session.
if (messageAction?.Title == takeActionText)
{
var command = new PSCommand().AddScript("powershell.exe -NoLogo -NoProfile -Command 'Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber'");

await _executionService.ExecutePSCommandAsync(
command,
CancellationToken.None,
new PowerShellExecutionOptions { WriteInputToHost = true, WriteOutputToHost = true, AddToHistory = true, ThrowOnError = false }).ConfigureAwait(false);

// TODO: Error handling here

/*
if (errors.Length == 0)
{
_logger.LogDebug("PackageManagement is updated.");
_languageServer.Window.ShowMessage(new ShowMessageParams
{
Type = MessageType.Info,
Message = "PackageManagement updated, If you already had PackageManagement loaded in your session, please restart the PowerShell extension."
});
}
else
{
// There were errors installing PackageManagement.
_logger.LogError($"PackageManagement installation had errors: {errors.ToString()}");
_languageServer.Window.ShowMessage(new ShowMessageParams
{
Type = MessageType.Error,
Message = "PackageManagement update failed. This might be due to PowerShell Gallery using TLS 1.2. More info can be found at https://aka.ms/psgallerytls"
});
}
*/
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,6 @@ private void SendFeatureChangesTelemetry(LanguageServerSettingsWrapper incomingS
configChanges["CodeFolding"] = incomingSettings.Powershell.CodeFolding.Enable;
}

// Send telemetry if the user opted-out of the prompt to update PackageManagement
if (!incomingSettings.Powershell.PromptToUpdatePackageManagement &&
_configurationService.CurrentSettings.PromptToUpdatePackageManagement != incomingSettings.Powershell.PromptToUpdatePackageManagement)
{
configChanges["PromptToUpdatePackageManagement"] = incomingSettings.Powershell.PromptToUpdatePackageManagement;
}

// Send telemetry if the user opted-out of Profile loading
if (!incomingSettings.Powershell.EnableProfileLoading &&
_configurationService.CurrentSettings.EnableProfileLoading != incomingSettings.Powershell.EnableProfileLoading)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ internal class LanguageServerSettings
{
private readonly object updateLock = new();
public bool EnableProfileLoading { get; set; }
public bool PromptToUpdatePackageManagement { get; set; } = true;
public ScriptAnalysisSettings ScriptAnalysis { get; set; }
public CodeFormattingSettings CodeFormatting { get; set; }
public CodeFoldingSettings CodeFolding { get; set; }
Expand All @@ -42,7 +41,6 @@ public void Update(
lock (updateLock)
{
EnableProfileLoading = settings.EnableProfileLoading;
PromptToUpdatePackageManagement = settings.PromptToUpdatePackageManagement;
ScriptAnalysis.Update(settings.ScriptAnalysis, workspaceRootPath, logger);
CodeFormatting = new CodeFormattingSettings(settings.CodeFormatting);
CodeFolding.Update(settings.CodeFolding, logger);
Expand Down