Skip to content

Commit 6fe3e48

Browse files
use powershell.exe
1 parent bbd1963 commit 6fe3e48

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

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

+9-19
Original file line numberDiff line numberDiff line change
@@ -110,39 +110,29 @@ private async Task CheckPackageManagement()
110110
// If the user chose "Not now" ignore it for the rest of the session.
111111
if (messageAction?.Title == takeActionText)
112112
{
113-
// Update PackageManagement
114-
PSCommand psCommand = new PSCommand()
115-
.AddCommand("Install-Module")
116-
.AddParameter("Name", "PackageManagement")
117-
.AddParameter("Force")
118-
.AddParameter("MinimumVersion", s_desiredPackageManagementVersion)
119-
.AddParameter("Scope", "CurrentUser")
120-
.AddParameter("AllowClobber");
121-
122113
StringBuilder errors = new StringBuilder();
123-
await _powerShellContextService.ExecuteCommandAsync<object>(psCommand, errors, new ExecutionOptions
124-
{
125-
WriteInputToHost = true,
126-
WriteErrorsToHost = true,
127-
WriteOutputToHost = true,
128-
InputString = "Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber"
129-
}).ConfigureAwait(false);
114+
await _powerShellContextService.ExecuteScriptStringAsync(
115+
"powershell.exe -NoLogo -NoProfile -Command 'Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber'",
116+
errors,
117+
writeInputToHost: true,
118+
writeOutputToHost: true,
119+
addToHistory: true).ConfigureAwait(false);
130120

131121
// There were errors installing PackageManagement.
132122
if (errors.Length == 0)
133123
{
134124
_languageServer.Window.ShowMessage(new ShowMessageParams
135125
{
136-
Type = MessageType.Warning,
137-
Message = "PackageManagement updated, please restart the PowerShell extension."
126+
Type = MessageType.Info,
127+
Message = "PackageManagement updated, If you already had PackageManagement loaded in your session, please restart the PowerShell extension."
138128
});
139129
}
140130
else
141131
{
142132
_languageServer.Window.ShowMessage(new ShowMessageParams
143133
{
144134
Type = MessageType.Error,
145-
Message = "PackageManagement update failed. Please run the following command in a Windows PowerShell prompt and restart the PowerShell extension: `Install-Module PackageManagement -Force -AllowClobber`"
135+
Message = "PackageManagement update failed. Please run the following command in a Windows PowerShell prompt and restart the PowerShell extension: `Install-Module PackageManagement -Force -AllowClobber -MinimumVersion 1.4.6`"
146136
});
147137
}
148138
}

0 commit comments

Comments
 (0)