From 7196ff773f875f307d369b47641849f6ca0d7d14 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sun, 28 May 2017 16:28:39 -0600 Subject: [PATCH 1/2] Catch up merge from master. --- src/session.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/session.ts b/src/session.ts index 811e355f43..88f40ca524 100644 --- a/src/session.ts +++ b/src/session.ts @@ -604,6 +604,21 @@ export class SessionManager { } } + private getPowerShellCorePaths(): string[] { + var paths: string[] = []; + if (this.isWindowsOS) { + const rootInstallPath = process.env.ProgramFiles + '\\PowerShell' + + var dirs = + fs.readdirSync(rootInstallPath) + .filter(file => fs.lstatSync(path.join(rootInstallPath, file)).isDirectory()); + + paths.concat(dirs); + } + + return paths; + } + private getBuiltInPowerShellPath(use32Bit: boolean): string | null { // Find the path to powershell.exe based on the current platform From 9c91aa63e18bc83005f245119b0ce30cdd5098c9 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Tue, 30 May 2017 15:26:23 -0600 Subject: [PATCH 2/2] Add session support for PS Core installs. --- src/session.ts | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/session.ts b/src/session.ts index 88f40ca524..005b447131 100644 --- a/src/session.ts +++ b/src/session.ts @@ -607,13 +607,19 @@ export class SessionManager { private getPowerShellCorePaths(): string[] { var paths: string[] = []; if (this.isWindowsOS) { - const rootInstallPath = process.env.ProgramFiles + '\\PowerShell' + const is64Bit = process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432'); + const rootInstallPath = (is64Bit ? process.env.ProgramW6432 : process.env.ProgramFiles) + '\\PowerShell'; - var dirs = - fs.readdirSync(rootInstallPath) - .filter(file => fs.lstatSync(path.join(rootInstallPath, file)).isDirectory()); + if (fs.existsSync(rootInstallPath)) { + var dirs = + fs.readdirSync(rootInstallPath) + .map(item => path.join(rootInstallPath, item)) + .filter(item => fs.lstatSync(item).isDirectory()); - paths.concat(dirs); + if (dirs) { + paths = paths.concat(dirs); + } + } } return paths; @@ -726,6 +732,19 @@ export class SessionManager { "Switch to Windows PowerShell (x64)", () => { this.restartSession({ type: SessionType.UseBuiltIn, is32Bit: false }) }); + var pscorePaths = this.getPowerShellCorePaths(); + for (var pscorePath of pscorePaths) { + var pscoreVersion = path.parse(pscorePath).base; + var pscoreExePath = path.join(pscorePath, "powershell.exe"); + var pscoreItem = new SessionMenuItem( + `Switch to PowerShell Core ${pscoreVersion}`, + () => { this.restartSession({ + type: SessionType.UsePath, path: pscoreExePath, isWindowsDevBuild: false }) + }); + + menuItems.push(pscoreItem); + } + // If the configured PowerShell path isn't being used, offer it as an option if (this.sessionSettings.developer.powerShellExePath !== "" && (this.sessionConfiguration.type !== SessionType.UsePath ||