Skip to content

Commit 6e5bea7

Browse files
Remove PackageManagement module update prompt (#1735)
The reason we attempted to update `PackageManagement` is no longer applicable (the deadlock has been fixed) so now we don't have to won this logic. Fixes #1576 and #1721.
1 parent cad2aa7 commit 6e5bea7

File tree

3 files changed

+0
-91
lines changed

3 files changed

+0
-91
lines changed

src/PowerShellEditorServices/Services/PowerShell/Handlers/GetVersionHandler.cs

-82
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ namespace Microsoft.PowerShell.EditorServices.Handlers
1919
{
2020
internal class GetVersionHandler : IGetVersionHandler
2121
{
22-
private static readonly Version s_desiredPackageManagementVersion = new Version(1, 4, 6);
23-
2422
private readonly ILogger<GetVersionHandler> _logger;
2523
private IRunspaceContext _runspaceContext;
2624
private readonly IInternalPowerShellExecutionService _executionService;
@@ -58,11 +56,6 @@ public async Task<PowerShellVersion> Handle(GetVersionParams request, Cancellati
5856
}
5957
}
6058

61-
if (VersionUtils.IsPS5 && _configurationService.CurrentSettings.PromptToUpdatePackageManagement)
62-
{
63-
await CheckPackageManagement().ConfigureAwait(false);
64-
}
65-
6659
return new PowerShellVersion
6760
{
6861
Version = VersionUtils.PSVersionString,
@@ -78,80 +71,5 @@ private enum PowerShellProcessArchitecture
7871
X86,
7972
X64
8073
}
81-
82-
private async Task CheckPackageManagement()
83-
{
84-
PSCommand getModule = new PSCommand().AddCommand("Get-Module").AddParameter("ListAvailable").AddParameter("Name", "PackageManagement");
85-
foreach (PSModuleInfo module in await _executionService.ExecutePSCommandAsync<PSModuleInfo>(getModule, CancellationToken.None).ConfigureAwait(false))
86-
{
87-
// The user has a good enough version of PackageManagement
88-
if (module.Version >= s_desiredPackageManagementVersion)
89-
{
90-
break;
91-
}
92-
93-
_logger.LogDebug("Old version of PackageManagement detected.");
94-
95-
if (_runspaceContext.CurrentRunspace.Runspace.SessionStateProxy.LanguageMode != PSLanguageMode.FullLanguage)
96-
{
97-
_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`");
98-
return;
99-
}
100-
101-
var takeActionText = "Yes";
102-
MessageActionItem messageAction = await _languageServer.Window.ShowMessageRequest(new ShowMessageRequestParams
103-
{
104-
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)?",
105-
Type = MessageType.Warning,
106-
Actions = new[]
107-
{
108-
new MessageActionItem
109-
{
110-
Title = takeActionText
111-
},
112-
new MessageActionItem
113-
{
114-
Title = "Not now"
115-
}
116-
}
117-
})
118-
.ConfigureAwait(false);
119-
120-
// If the user chose "Not now" ignore it for the rest of the session.
121-
if (messageAction?.Title == takeActionText)
122-
{
123-
var command = new PSCommand().AddScript("powershell.exe -NoLogo -NoProfile -Command 'Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber'");
124-
125-
await _executionService.ExecutePSCommandAsync(
126-
command,
127-
CancellationToken.None,
128-
new PowerShellExecutionOptions { WriteInputToHost = true, WriteOutputToHost = true, AddToHistory = true, ThrowOnError = false }).ConfigureAwait(false);
129-
130-
// TODO: Error handling here
131-
132-
/*
133-
if (errors.Length == 0)
134-
{
135-
_logger.LogDebug("PackageManagement is updated.");
136-
_languageServer.Window.ShowMessage(new ShowMessageParams
137-
{
138-
Type = MessageType.Info,
139-
Message = "PackageManagement updated, If you already had PackageManagement loaded in your session, please restart the PowerShell extension."
140-
});
141-
}
142-
else
143-
{
144-
// There were errors installing PackageManagement.
145-
_logger.LogError($"PackageManagement installation had errors: {errors.ToString()}");
146-
_languageServer.Window.ShowMessage(new ShowMessageParams
147-
{
148-
Type = MessageType.Error,
149-
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"
150-
});
151-
}
152-
*/
153-
}
154-
}
155-
}
15674
}
15775
}

src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs

-7
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,6 @@ private void SendFeatureChangesTelemetry(LanguageServerSettingsWrapper incomingS
203203
configChanges["CodeFolding"] = incomingSettings.Powershell.CodeFolding.Enable;
204204
}
205205

206-
// Send telemetry if the user opted-out of the prompt to update PackageManagement
207-
if (!incomingSettings.Powershell.PromptToUpdatePackageManagement &&
208-
_configurationService.CurrentSettings.PromptToUpdatePackageManagement != incomingSettings.Powershell.PromptToUpdatePackageManagement)
209-
{
210-
configChanges["PromptToUpdatePackageManagement"] = incomingSettings.Powershell.PromptToUpdatePackageManagement;
211-
}
212-
213206
// Send telemetry if the user opted-out of Profile loading
214207
if (!incomingSettings.Powershell.EnableProfileLoading &&
215208
_configurationService.CurrentSettings.EnableProfileLoading != incomingSettings.Powershell.EnableProfileLoading)

src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ internal class LanguageServerSettings
1717
{
1818
private readonly object updateLock = new();
1919
public bool EnableProfileLoading { get; set; }
20-
public bool PromptToUpdatePackageManagement { get; set; } = true;
2120
public ScriptAnalysisSettings ScriptAnalysis { get; set; }
2221
public CodeFormattingSettings CodeFormatting { get; set; }
2322
public CodeFoldingSettings CodeFolding { get; set; }
@@ -42,7 +41,6 @@ public void Update(
4241
lock (updateLock)
4342
{
4443
EnableProfileLoading = settings.EnableProfileLoading;
45-
PromptToUpdatePackageManagement = settings.PromptToUpdatePackageManagement;
4644
ScriptAnalysis.Update(settings.ScriptAnalysis, workspaceRootPath, logger);
4745
CodeFormatting = new CodeFormattingSettings(settings.CodeFormatting);
4846
CodeFolding.Update(settings.CodeFolding, logger);

0 commit comments

Comments
 (0)