Skip to content

microsoft store installed powershell can not be recognized #3181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Wongboo opened this issue Feb 13, 2021 · 6 comments · Fixed by #3202
Closed

microsoft store installed powershell can not be recognized #3181

Wongboo opened this issue Feb 13, 2021 · 6 comments · Fixed by #3202
Labels

Comments

@Wongboo
Copy link

Wongboo commented Feb 13, 2021

I used to use powershell delivered by github release, now as I favor the convenience of microsoft-store's integrated update, I switch to powershell in microsoft store.
But then bugs appear:

  1. vscode-powershell cannot automatically recognize microsoft store installed powershell
  2. even if I changed “PowerShell Additional Exe Paths” in JSON with the value
    $PSHOME\pwsh.exe which is
    "C:\Program Files\WindowsApps\Microsoft.PowerShellPreview_7.2.2.0_x64__8wekyb3d8bbwe\pwsh.exe"
    vscode-powershell cannot recognize microsoft store installed powershell as well
@ghost ghost added the Needs: Triage Maintainer attention needed! label Feb 13, 2021
@Wongboo
Copy link
Author

Wongboo commented Feb 13, 2021

I tried to change "terminal.integrated.shell.windows" as well,but no use

@Softgrider
Copy link

This happens since updated to Visual Studio Code Version 1.53.
Uninstall Store Version and install msi Version brings the powershell 7.1.x back

@rjmholt
Copy link
Contributor

rjmholt commented Feb 16, 2021

The logic to automatically pick up a store installation is here:

private findPSCoreMsix({ findPreview }: { findPreview?: boolean } = {}): IPossiblePowerShellExe {
// We can't proceed if there's no LOCALAPPDATA path
if (!process.env.LOCALAPPDATA) {
return null;
}
// Find the base directory for MSIX application exe shortcuts
const msixAppDir = path.join(process.env.LOCALAPPDATA, "Microsoft", "WindowsApps");
if (!fs.existsSync(msixAppDir)) {
return null;
}
// Define whether we're looking for the preview or the stable
const { pwshMsixDirRegex, pwshMsixName } = findPreview
? { pwshMsixDirRegex: PowerShellExeFinder.PwshPreviewMsixRegex, pwshMsixName: "PowerShell Preview (Store)" }
: { pwshMsixDirRegex: PowerShellExeFinder.PwshMsixRegex, pwshMsixName: "PowerShell (Store)" };
// We should find only one such application, so return on the first one
for (const subdir of fs.readdirSync(msixAppDir)) {
if (pwshMsixDirRegex.test(subdir)) {
const pwshMsixPath = path.join(msixAppDir, subdir, "pwsh.exe");
return new PossiblePowerShellExe(pwshMsixPath, pwshMsixName);
}
}
// If we find nothing, return null
return null;
}

It's not clear why this would suddenly fail, especially due to a VSCode update (since that shouldn't update anything within the extension itself).

It's also mysterious why giving an explicit absolute path would also fail -- that's effectively a bypass for the PowerShell-finding logic and should work no matter where it's pointed (as long as that's a valid PowerShell executable).

@rjmholt
Copy link
Contributor

rjmholt commented Feb 19, 2021

So we've now had a second report of this, and I'm wondering if there's a permissions issue or similar going on -- hopefully we can reproduce this locally to investigate

@wjvii
Copy link

wjvii commented Feb 19, 2021

@rjmholt I can confirm the same behavior here as well.

@rjmholt
Copy link
Contributor

rjmholt commented Feb 23, 2021

So it looks like this is due to fs.existsSync returning false for symlinks, causing this to be false here:

this.knownToExist = fs.existsSync(this.exePath);

It's not clear why this previously worked, but either node or Windows/the store has changed its behaviour here (our code hasn't changed since we implemented Store PowerShell detection).

We need to update this check to be something like:

try {
    fs.lstatSync(this.exePath);
    this.knownToExist = true;
} catch {
    this.knownToExist = false;
}

Or alternatively do a readlink operation to resolve the link...

@SydneyhSmith SydneyhSmith removed the Needs: Triage Maintainer attention needed! label Feb 23, 2021
@SydneyhSmith SydneyhSmith added this to the Consider-vNext milestone Feb 23, 2021
andyleejordan pushed a commit that referenced this issue Feb 25, 2021
Fixes #3181.

The MSIX exe is a symlink and node's file test API returns false for those.

This fixes that so we now detect the PowerShell MSIX installation properly again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants