vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Inconsistent behavior for working directory when running scripts

Open fflaten opened this issue 3 years ago • 0 comments

Prerequisites

  • [X] I have written a descriptive issue title.
  • [X] I have searched all open and closed issues to ensure it has not already been reported.
  • [X] I have read the troubleshooting guide.
  • [X] I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • [X] 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

#3259 was recently fixed so the integrated console doesn't change CWD when using "Run/Debug Tests". However there are still commands and config that enforces and promotes unnecessary CWD-changes.

The first command should not change working directory in my opinion. The suggested launch config should also leave it unchanged (set to cwd: ""). People can change it if they want/need it.

This change would also encourage users to rely on $PSScriptRoot when referencing files relative to the script. I believe that's a good practice since working directory is rarely specified when running scripts in my experience.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.2.5
PSEdition                      Core
GitCommitId                    7.2.5
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.70.0-insider
1cd90cceddf3c413673963ab6f154d2ff294b17c
x64

Extension Version

[email protected]

Steps to Reproduce

Scenario 1:

  1. Create a powershell-file in a different directory than the integrated console's cwd/pwd
  2. Press the play-button or use PowerShell: Run command

Scenario 2:

  1. Add a launch configuration for Launch current file
  2. Press F5 in a powershell-file that's placed in a different folder than the integrated console's cwd/pwd

The cwd/pwd in integrated console will be changed.

Visuals

No response

Logs

No response

fflaten avatar Jul 16 '22 23:07 fflaten