diff --git a/lib/find-visualstudio.js b/lib/find-visualstudio.js index be0ca6a814..31ddf1259d 100644 --- a/lib/find-visualstudio.js +++ b/lib/find-visualstudio.js @@ -125,40 +125,40 @@ VisualStudioFinder.prototype = { // Invoke the PowerShell script to get information about Visual Studio 2017 // or newer installations - findVisualStudio2017OrNewer: function findVisualStudio2017OrNewer(cb) { + findVisualStudio2017OrNewer: function findVisualStudio2017OrNewer (cb) { const ps = path.join(process.env.SystemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe') const csFile = path.join(__dirname, 'Find-VisualStudio.cs') const basePsArgs = ['-ExecutionPolicy', 'Unrestricted', '-NoProfile', '-Command',] const findLanguageModePsCmd = - `&{ try { $ExecutionContext.SessionState.LanguageMode } catch { try { (Get-PSSessionConfiguration -Name Test).LanguageMode } catch { 'error' } } }` + `&{ try { $ExecutionContext.SessionState.LanguageMode } catch { try { (Get-PSSessionConfiguration -Name Test).LanguageMode } catch { 'error' } } }` const psArgs = [...basePsArgs, findLanguageModePsCmd] this.log.silly('Running', ps, psArgs) const childFindPsLanguageMode = execFile( - ps, - psArgs, - {encoding: 'utf8'}, - (err, stdout, stderr) => { - this.log.silly('PS stderr = %j', stderr) - if (err) { - this.log.silly('PS err = %j', err && (err.stack || err)) - this.addLog( - 'could not determine PowerShell LanguageMode, try re-running with \'--loglevel silly\' for more details') - return cb(null) - } - const findVscDataPsCmd = `&{Add-Type -Path '${csFile}';[VisualStudioConfiguration.Main]::PrintJson()}` - const psArgs = [...basePsArgs, findVscDataPsCmd] - // the Add-Type command requires powershell to run with languageMode == FullLanguage - // Because languageMode feature is not introduced yet in powershell v2, we can try to use it. - // If powershell v2 is not installed (a problem only if languageMode is not FullLanguage), then it is not - // possible to use feature Add-Type. - if (stdout.toString('utf8').trim().toLowerCase() !== 'fulllanguage') { - psArgs.unshift('-Version', '2',) - } - this.log.silly('Running', ps, psArgs) - const child = execFile(ps, psArgs, {encoding: 'utf8'}, (err, stdout, stderr) => this.parseData(err, stdout, stderr, cb)) - child.stdin.end() - }) + ps, + psArgs, + { encoding: 'utf8' }, + (err, stdout, stderr) => { + this.log.silly('PS stderr = %j', stderr) + if (err) { + this.log.silly('PS err = %j', err && (err.stack || err)) + this.addLog( + 'could not determine PowerShell LanguageMode, try re-running with \'--loglevel silly\' for more details') + return cb(null) + } + const findVscDataPsCmd = `&{Add-Type -Path '${csFile}';[VisualStudioConfiguration.Main]::PrintJson()}` + const psArgs = [...basePsArgs, findVscDataPsCmd] + // the Add-Type command requires powershell to run with languageMode == FullLanguage + // Because languageMode feature is not introduced yet in powershell v2, we can try to use it. + // If powershell v2 is not installed (a problem only if languageMode is not FullLanguage), then it is not + // possible to use feature Add-Type. + if (stdout.toString('utf8').trim().toLowerCase() !== 'fulllanguage') { + psArgs.unshift('-Version', '2',) + } + this.log.silly('Running', ps, psArgs) + const child = execFile(ps, psArgs, { encoding: 'utf8' }, (err, stdout, stderr) => this.parseData(err, stdout, stderr, cb)) + child.stdin.end() + }) childFindPsLanguageMode.stdin.end() },