Skip to content

Commit da16995

Browse files
committed
Suppress startup banner for dotnet global install of PowerShell
1 parent 75e2460 commit da16995

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

src/platform.ts

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface IPlatformDetails {
3838
export interface IPowerShellExeDetails {
3939
readonly displayName: string;
4040
readonly exePath: string;
41+
readonly supportsProperArguments: boolean;
4142
}
4243

4344
export function getPlatformDetails(): IPlatformDetails {
@@ -266,6 +267,7 @@ export class PowerShellExeFinder {
266267

267268
const dotnetGlobalToolExePath: string = path.join(os.homedir(), ".dotnet", "tools", exeName);
268269

270+
// The dotnet installed version of PowerShell does not support proper argument parsing, and so it fails with our multi-line startup banner.
269271
return new PossiblePowerShellExe(dotnetGlobalToolExePath, ".NET Core PowerShell Global Tool", undefined, false);
270272
}
271273

src/process.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import vscode = require("vscode");
99
import { Logger } from "./logging";
1010
import Settings = require("./settings");
1111
import utils = require("./utils");
12-
import { IEditorServicesSessionDetails, SessionManager } from "./session";
12+
import { IEditorServicesSessionDetails } from "./session";
1313

1414
export class PowerShellProcess {
1515
public static escapeSingleQuotes(psPath: string): string {
@@ -83,12 +83,14 @@ export class PowerShellProcess {
8383
PowerShellProcess.escapeSingleQuotes(psesModulePath) +
8484
"'; Start-EditorServices " + this.startPsesArgs;
8585

86+
// On Windows we unfortunately can't Base64 encode the startup command
87+
// because it annoys some poorly implemented anti-virus scanners.
8688
if (utils.isWindows) {
8789
powerShellArgs.push(
8890
"-Command",
8991
startEditorServices);
9092
} else {
91-
// Use -EncodedCommand for better quote support on non-Windows
93+
// Otherwise use -EncodedCommand for better quote support.
9294
powerShellArgs.push(
9395
"-EncodedCommand",
9496
Buffer.from(startEditorServices, "utf16le").toString("base64"));

src/session.ts

+7
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ export class SessionManager implements Middleware {
215215

216216
if (this.sessionSettings.integratedConsole.suppressStartupBanner) {
217217
this.editorServicesArgs += "-StartupBanner '' ";
218+
} else if (utils.isWindows && !this.PowerShellExeDetails.supportsProperArguments) {
219+
// NOTE: On Windows we don't Base64 encode the startup command
220+
// because it annoys some poorly implemented anti-virus scanners.
221+
// Unfortunately this means that for some installs of PowerShell
222+
// (such as through the `dotnet` package manager), we can't include
223+
// a multi-line startup banner as the quotes break the command.
224+
this.editorServicesArgs += `-StartupBanner '${this.HostName} Extension v${this.HostVersion}' `;
218225
} else {
219226
const startupBanner = `${this.HostName} Extension v${this.HostVersion}
220227
Copyright (c) Microsoft Corporation.

test/core/platform.test.ts

+35-9
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,42 @@ if (process.platform === "win32") {
7777
{
7878
exePath: "C:\\Program Files\\PowerShell\\6\\pwsh.exe",
7979
displayName: "PowerShell (x64)",
80+
supportsProperArguments: true
8081
},
8182
{
8283
exePath: "C:\\Program Files (x86)\\PowerShell\\6\\pwsh.exe",
8384
displayName: "PowerShell (x86)",
85+
supportsProperArguments: true
8486
},
8587
{
8688
exePath: pwshMsixPath,
8789
displayName: "PowerShell (Store)",
90+
supportsProperArguments: true
8891
},
8992
{
9093
exePath: "C:\\Program Files\\PowerShell\\7-preview\\pwsh.exe",
9194
displayName: "PowerShell Preview (x64)",
95+
supportsProperArguments: true
9296
},
9397
{
9498
exePath: pwshPreviewMsixPath,
9599
displayName: "PowerShell Preview (Store)",
100+
supportsProperArguments: true
96101
},
97102
{
98103
exePath: "C:\\Program Files (x86)\\PowerShell\\7-preview\\pwsh.exe",
99104
displayName: "PowerShell Preview (x86)",
105+
supportsProperArguments: true
100106
},
101107
{
102108
exePath: "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
103109
displayName: "Windows PowerShell (x64)",
110+
supportsProperArguments: true
104111
},
105112
{
106113
exePath: "C:\\WINDOWS\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe",
107114
displayName: "Windows PowerShell (x86)",
115+
supportsProperArguments: true
108116
},
109117
],
110118
filesystem: {
@@ -156,10 +164,12 @@ if (process.platform === "win32") {
156164
{
157165
exePath: "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
158166
displayName: "Windows PowerShell (x64)",
167+
supportsProperArguments: true
159168
},
160169
{
161170
exePath: "C:\\WINDOWS\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe",
162171
displayName: "Windows PowerShell (x86)",
172+
supportsProperArguments: true
163173
},
164174
],
165175
filesystem: {
@@ -187,34 +197,42 @@ if (process.platform === "win32") {
187197
{
188198
exePath: "C:\\Program Files (x86)\\PowerShell\\6\\pwsh.exe",
189199
displayName: "PowerShell (x86)",
200+
supportsProperArguments: true
190201
},
191202
{
192203
exePath: "C:\\Program Files\\PowerShell\\6\\pwsh.exe",
193204
displayName: "PowerShell (x64)",
205+
supportsProperArguments: true
194206
},
195207
{
196208
exePath: pwshMsixPath,
197209
displayName: "PowerShell (Store)",
210+
supportsProperArguments: true
198211
},
199212
{
200213
exePath: "C:\\Program Files (x86)\\PowerShell\\7-preview\\pwsh.exe",
201214
displayName: "PowerShell Preview (x86)",
215+
supportsProperArguments: true
202216
},
203217
{
204218
exePath: pwshPreviewMsixPath,
205219
displayName: "PowerShell Preview (Store)",
220+
supportsProperArguments: true
206221
},
207222
{
208223
exePath: "C:\\Program Files\\PowerShell\\7-preview\\pwsh.exe",
209224
displayName: "PowerShell Preview (x64)",
225+
supportsProperArguments: true
210226
},
211227
{
212228
exePath: "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
213229
displayName: "Windows PowerShell (x86)",
230+
supportsProperArguments: true
214231
},
215232
{
216233
exePath: "C:\\WINDOWS\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
217234
displayName: "Windows PowerShell (x64)",
235+
supportsProperArguments: true
218236
},
219237
],
220238
filesystem: {
@@ -266,10 +284,12 @@ if (process.platform === "win32") {
266284
{
267285
exePath: "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
268286
displayName: "Windows PowerShell (x86)",
287+
supportsProperArguments: true
269288
},
270289
{
271290
exePath: "C:\\WINDOWS\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
272291
displayName: "Windows PowerShell (x64)",
292+
supportsProperArguments: true
273293
},
274294
],
275295
filesystem: {
@@ -297,22 +317,27 @@ if (process.platform === "win32") {
297317
{
298318
exePath: "C:\\Program Files (x86)\\PowerShell\\6\\pwsh.exe",
299319
displayName: "PowerShell (x86)",
320+
supportsProperArguments: true
300321
},
301322
{
302323
exePath: pwshMsixPath,
303324
displayName: "PowerShell (Store)",
325+
supportsProperArguments: true
304326
},
305327
{
306328
exePath: "C:\\Program Files (x86)\\PowerShell\\7-preview\\pwsh.exe",
307329
displayName: "PowerShell Preview (x86)",
330+
supportsProperArguments: true
308331
},
309332
{
310333
exePath: pwshPreviewMsixPath,
311334
displayName: "PowerShell Preview (Store)",
335+
supportsProperArguments: true
312336
},
313337
{
314338
exePath: "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
315339
displayName: "Windows PowerShell (x86)",
340+
supportsProperArguments: true
316341
},
317342
],
318343
filesystem: {
@@ -353,6 +378,7 @@ if (process.platform === "win32") {
353378
{
354379
exePath: "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
355380
displayName: "Windows PowerShell (x86)",
381+
supportsProperArguments: true
356382
},
357383
],
358384
filesystem: {
@@ -372,10 +398,10 @@ if (process.platform === "win32") {
372398
isProcess64Bit: true,
373399
},
374400
expectedPowerShellSequence: [
375-
{ exePath: "/usr/bin/pwsh", displayName: "PowerShell" },
376-
{ exePath: "/snap/bin/pwsh", displayName: "PowerShell Snap" },
377-
{ exePath: "/usr/bin/pwsh-preview", displayName: "PowerShell Preview" },
378-
{ exePath: "/snap/bin/pwsh-preview", displayName: "PowerShell Preview Snap" },
401+
{ exePath: "/usr/bin/pwsh", displayName: "PowerShell", supportsProperArguments: true },
402+
{ exePath: "/snap/bin/pwsh", displayName: "PowerShell Snap", supportsProperArguments: true },
403+
{ exePath: "/usr/bin/pwsh-preview", displayName: "PowerShell Preview", supportsProperArguments: true },
404+
{ exePath: "/snap/bin/pwsh-preview", displayName: "PowerShell Preview Snap", supportsProperArguments: true },
379405
],
380406
filesystem: {
381407
"/usr/bin": {
@@ -396,8 +422,8 @@ if (process.platform === "win32") {
396422
isProcess64Bit: true,
397423
},
398424
expectedPowerShellSequence: [
399-
{ exePath: "/usr/local/bin/pwsh", displayName: "PowerShell" },
400-
{ exePath: "/usr/local/bin/pwsh-preview", displayName: "PowerShell Preview" },
425+
{ exePath: "/usr/local/bin/pwsh", displayName: "PowerShell", supportsProperArguments: true },
426+
{ exePath: "/usr/local/bin/pwsh-preview", displayName: "PowerShell Preview", supportsProperArguments: true },
401427
],
402428
filesystem: {
403429
"/usr/local/bin": {
@@ -414,7 +440,7 @@ if (process.platform === "win32") {
414440
isProcess64Bit: true,
415441
},
416442
expectedPowerShellSequence: [
417-
{ exePath: "/usr/bin/pwsh", displayName: "PowerShell" },
443+
{ exePath: "/usr/bin/pwsh", displayName: "PowerShell", supportsProperArguments: true },
418444
],
419445
filesystem: {
420446
"/usr/bin": {
@@ -430,7 +456,7 @@ if (process.platform === "win32") {
430456
isProcess64Bit: true,
431457
},
432458
expectedPowerShellSequence: [
433-
{ exePath: "/snap/bin/pwsh", displayName: "PowerShell Snap" },
459+
{ exePath: "/snap/bin/pwsh", displayName: "PowerShell Snap", supportsProperArguments: true },
434460
],
435461
filesystem: {
436462
"/snap/bin": {
@@ -446,7 +472,7 @@ if (process.platform === "win32") {
446472
isProcess64Bit: true,
447473
},
448474
expectedPowerShellSequence: [
449-
{ exePath: "/usr/local/bin/pwsh", displayName: "PowerShell" },
475+
{ exePath: "/usr/local/bin/pwsh", displayName: "PowerShell", supportsProperArguments: true },
450476
],
451477
filesystem: {
452478
"/usr/local/bin": {

0 commit comments

Comments
 (0)