Skip to content

Inconsistent behavior for working directory when running scripts #4082

Closed
@fflaten

Description

@fflaten

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

#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

ms-vscode.powershell-preview@2022.7.0

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions