Skip to content
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

Current directory is included in PowerShell "launch" option; breaking launch configurations that run a command #3537

Closed
4 tasks done
JamesLear92 opened this issue Aug 31, 2021 · 11 comments · Fixed by PowerShell/PowerShellEditorServices#1569
Assignees
Labels

Comments

@JamesLear92
Copy link

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

I like to run PowerShell scripts into external windows. I have been using the same launch configs for years now without problem, but suddenly none of them now work. Here is an example launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "PowerShell",
            "request": "launch",
            "name": "PS5",
            "script": "Start-Process",
            "args": [
                "-FilePath ($Env:SystemRoot + '\\system32\\WindowsPowerShell\\v1.0\\powershell.exe')",
                "-Argumentlist '-NoExit -NoProfile -ExecutionPolicy Bypass -File \"${file}\"'"
            ]
        }
    ]
}

What should happen when running launching a .PS1 file with the debug option, is this:

PS C:\Test> Start-Process -FilePath ($Env:SystemRoot + '\system32\WindowsPowerShell\v1.0\powershell.exe') -Argumentlist '-NoExit -NoProfile -ExecutionPolicy Bypass -File "c:\Users\TestUser\desktop\TestScript.PS1"'

However it actually runs:

PS C:\Test> C:\Test\Start-Process -FilePath ($Env:SystemRoot + '\system32\WindowsPowerShell\v1.0\powershell.exe') -Argumentlist '-NoExit -NoProfile -ExecutionPolicy Bypass -File "c:\Users\TestUser\desktop\TestScript.PS1"'

Which of course leads to the error message:

C:\Test\Start-Process: The term 'C:\Test\Start-Process' is not recognized as a name of a cmdlet, function, script file, or executable program.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.1.4
PSEdition                      Core
GitCommitId                    7.1.4
OS                             Microsoft Windows 10.0.19042
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.59.1
3866c3553be8b268c8a7f8c0482c0c0177aa8bfa
x64

Extension Version

ms-vscode.powershell-preview@2021.8.2

Steps to Reproduce

Use the Launch config from above, and select it as the debug option. Then attempt to run any SAVED script.

Visuals

No response

Logs

No response

@JamesLear92 JamesLear92 added the Issue-Bug A bug to squash. label Aug 31, 2021
@ghost ghost added the Needs: Triage Maintainer attention needed! label Aug 31, 2021
@JamesLear92
Copy link
Author

JamesLear92 commented Aug 31, 2021

Versions with problem:
ms-vscode.powershell-preview@2021.8.3
ms-vscode.powershell@2021.8.2

Versions without problem:
ms-vscode.powershell-preview@2021.8.0
ms-vscode.powershell@2021.8.0

@andyleejordan
Copy link
Member

Oh, crap, sorry about that.

@andyleejordan andyleejordan pinned this issue Aug 31, 2021
@andyleejordan andyleejordan added Area-Debugging and removed Needs: Triage Maintainer attention needed! labels Aug 31, 2021
@andyleejordan
Copy link
Member

I guess I'm not totally sure why this is happening. I mean, I'm certain it's because of 8ebbb55, but that implies that your custom configuration was taking a default value for cwd from the first configuration snippet instead of the launch configuration's defaults. I guess I'm trying to say that if VS Code did the obvious thing and used the configured default here:

"cwd": {
"type": "string",
"description": "Absolute path to the working directory. Default is the current workspace folder.",
"default": "${workspaceFolder}"
},

Then this would have been broken all along as that remained unchanged. It was last touched in #1397

Instead of reverting that commit, I'd like to figure out the best way to fix this.

@rkeithhill do you have any idea?

@andyleejordan
Copy link
Member

Also in case you haven't already figured this out, the work around should be to add "cwd": "" to your custom configuration.

@rkeithhill
Copy link
Contributor

I don't think this has anything to do with the cwd field. The script field name was picked because we wanted to allow not just a filename but arbitrary script e.g. "script": "Invoke-Pester". It seems that something (either the extension or PSES) is prepending a path to the script field value assuming it always specifies a path to a PS1 file. Whatever it is, It should not make that assumption.

BTW this only seems to happen when you specify "args": so there must be something about argument processing that is causing this. Ah, this is from the PSES log file:

2021-08-31 14:53:45.541 -06:00 [VRB] Prepending working directory C:\Users\Keith\.vscode\extensions\ms-vscode.powershell-2021.8.2\examples\Tests to script path Invoke-Pester

Yeah, that's yer problem right there.

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Aug 31, 2021
@andyleejordan
Copy link
Member

Interesting...I will dig into PSES changes and see how we broke it. Thanks Keith!

@andyleejordan
Copy link
Member

Ah, it was PowerShell/PowerShellEditorServices@da43937 🙃

@andyleejordan
Copy link
Member

All right. Fixed this and covered it with a test. Will get it into the next preview.

@andyleejordan
Copy link
Member

Thanks for the issue! Keep them coming.

@JamesLear92
Copy link
Author

Awesome work, thanks for the quick fix.

@andyleejordan
Copy link
Member

This fix is available in the preview that went out yesterday!

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.

4 participants