Skip to content

Workspace folder pick pops up if a predefined variable is used for the powershell.cwd setting #4163

@lewis-yeung

Description

@lewis-yeung

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

The description for the powershell.cwd setting says:

Predefined variables can be used (i.e. ${fileDirname} to use the current opened file's directory).

However, even if a predefined variable (e.g., ${fileDirname} or ${fileWorkspaceFolder}) is used for powershell.cwd, whenever I open a PowerShell (.ps1) file in a multi-root workspace for the first time, it prompts me to choose a workspace folder as the working directory:

Select a folder to use as the PowerShell extension's working directory.

This is so annoying and should not happen. While if I use a literal path such as C:\, it works fine and the workspace folder pick does not pop up.

Other possibly related settings I use:

{
  "powershell.startAutomatically": true,
  "powershell.integratedConsole.showOnStartup": false,
  "powershell.integratedConsole.startInBackground": true
}

Possibly related code:

let cwd: string = vscode.workspace.getConfiguration(utils.PowerShellLanguageId).get<string>("cwd", undefined);
// Only use the cwd setting if it exists.
if (await utils.checkIfDirectoryExists(cwd)) {
return cwd;
}

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.71.0
784b0177c56c607789f9638da7b6bf3230d47a8c
x64

Extension Version

ms-vscode.powershell@2022.8.5

Steps to Reproduce

  1. Apply the following settings:
    {
      "powershell.cwd": "${fileWorkspaceFolder}",
      "powershell.startAutomatically": true,
      "powershell.integratedConsole.showOnStartup": false,
      "powershell.integratedConsole.startInBackground": true
    }
    where any other predefined variable (e.g., ${fileDirname}) can be used for powershell.cwd.
  2. Open a multi-root workspace in a new VS Code window.
  3. Open a PowerShell (.ps1) file, and the workspace folder pick will pop up.

Visuals

No response

Logs

No response

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions