Skip to content

Commit 2f3a59f

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

File tree

4 files changed

+110
-11
lines changed

4 files changed

+110
-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

+97-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: {
@@ -361,6 +387,26 @@ if (process.platform === "win32") {
361387
},
362388
},
363389
},
390+
{
391+
name: "Windows (dotnet)",
392+
platformDetails: {
393+
operatingSystem: platform.OperatingSystem.Windows,
394+
isOS64Bit: true,
395+
isProcess64Bit: true,
396+
},
397+
environmentVars: {
398+
"USERNAME": "test",
399+
"USERPROFILE": "C:\\Users\\test",
400+
},
401+
expectedPowerShellSequence: [
402+
{ exePath: "C:\\Users\\test\\tools\\pwsh.exe", displayName: ".NET Core PowerShell Global Tool", supportsProperArguments: false },
403+
],
404+
filesystem: {
405+
"C:\\Users\\test\\tools": {
406+
"pwsh.exe": "",
407+
},
408+
},
409+
},
364410
];
365411
} else {
366412
successTestCases = [
@@ -372,10 +418,10 @@ if (process.platform === "win32") {
372418
isProcess64Bit: true,
373419
},
374420
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" },
421+
{ exePath: "/usr/bin/pwsh", displayName: "PowerShell", supportsProperArguments: true },
422+
{ exePath: "/snap/bin/pwsh", displayName: "PowerShell Snap", supportsProperArguments: true },
423+
{ exePath: "/usr/bin/pwsh-preview", displayName: "PowerShell Preview", supportsProperArguments: true },
424+
{ exePath: "/snap/bin/pwsh-preview", displayName: "PowerShell Preview Snap", supportsProperArguments: true },
379425
],
380426
filesystem: {
381427
"/usr/bin": {
@@ -396,8 +442,8 @@ if (process.platform === "win32") {
396442
isProcess64Bit: true,
397443
},
398444
expectedPowerShellSequence: [
399-
{ exePath: "/usr/local/bin/pwsh", displayName: "PowerShell" },
400-
{ exePath: "/usr/local/bin/pwsh-preview", displayName: "PowerShell Preview" },
445+
{ exePath: "/usr/local/bin/pwsh", displayName: "PowerShell", supportsProperArguments: true },
446+
{ exePath: "/usr/local/bin/pwsh-preview", displayName: "PowerShell Preview", supportsProperArguments: true },
401447
],
402448
filesystem: {
403449
"/usr/local/bin": {
@@ -414,7 +460,7 @@ if (process.platform === "win32") {
414460
isProcess64Bit: true,
415461
},
416462
expectedPowerShellSequence: [
417-
{ exePath: "/usr/bin/pwsh", displayName: "PowerShell" },
463+
{ exePath: "/usr/bin/pwsh", displayName: "PowerShell", supportsProperArguments: true },
418464
],
419465
filesystem: {
420466
"/usr/bin": {
@@ -430,7 +476,7 @@ if (process.platform === "win32") {
430476
isProcess64Bit: true,
431477
},
432478
expectedPowerShellSequence: [
433-
{ exePath: "/snap/bin/pwsh", displayName: "PowerShell Snap" },
479+
{ exePath: "/snap/bin/pwsh", displayName: "PowerShell Snap", supportsProperArguments: true },
434480
],
435481
filesystem: {
436482
"/snap/bin": {
@@ -446,14 +492,54 @@ if (process.platform === "win32") {
446492
isProcess64Bit: true,
447493
},
448494
expectedPowerShellSequence: [
449-
{ exePath: "/usr/local/bin/pwsh", displayName: "PowerShell" },
495+
{ exePath: "/usr/local/bin/pwsh", displayName: "PowerShell", supportsProperArguments: true },
450496
],
451497
filesystem: {
452498
"/usr/local/bin": {
453499
pwsh: "",
454500
},
455501
},
456502
},
503+
{
504+
name: "MacOS (dotnet)",
505+
platformDetails: {
506+
operatingSystem: platform.OperatingSystem.MacOS,
507+
isOS64Bit: true,
508+
isProcess64Bit: true,
509+
},
510+
environmentVars: {
511+
"USER": "test",
512+
"HOME": "/Users/test",
513+
},
514+
expectedPowerShellSequence: [
515+
{ exePath: "/Users/test/.dotnet/tools/pwsh", displayName: ".NET Core PowerShell Global Tool", supportsProperArguments: false },
516+
],
517+
filesystem: {
518+
"/Users/test/.dotnet/tools": {
519+
pwsh: "",
520+
},
521+
},
522+
},
523+
{
524+
name: "Linux (dotnet)",
525+
platformDetails: {
526+
operatingSystem: platform.OperatingSystem.Linux,
527+
isOS64Bit: true,
528+
isProcess64Bit: true,
529+
},
530+
environmentVars: {
531+
"USER": "test",
532+
"HOME": "/home/test",
533+
},
534+
expectedPowerShellSequence: [
535+
{ exePath: "/home/test/.dotnet/tools/pwsh", displayName: ".NET Core PowerShell Global Tool", supportsProperArguments: false },
536+
],
537+
filesystem: {
538+
"/home/test/.dotnet/tools": {
539+
pwsh: "",
540+
},
541+
},
542+
},
457543
];
458544
}
459545

@@ -559,6 +645,7 @@ describe("Platform module", function () {
559645

560646
assert.strictEqual(defaultPowerShell.exePath, expectedPowerShell.exePath);
561647
assert.strictEqual(defaultPowerShell.displayName, expectedPowerShell.displayName);
648+
assert.strictEqual(defaultPowerShell.supportsProperArguments, expectedPowerShell.supportsProperArguments);
562649
});
563650
}
564651

@@ -594,6 +681,7 @@ describe("Platform module", function () {
594681

595682
assert.strictEqual(foundPowerShell && foundPowerShell.exePath, expectedPowerShell.exePath);
596683
assert.strictEqual(foundPowerShell && foundPowerShell.displayName, expectedPowerShell.displayName);
684+
assert.strictEqual(foundPowerShell && foundPowerShell.supportsProperArguments, expectedPowerShell.supportsProperArguments);
597685
}
598686

599687
assert.strictEqual(

0 commit comments

Comments
 (0)