Skip to content

v2022.10.0 may cause previous "script" values in launch.json fail to execute #4223

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
2 of 6 tasks
changbowen opened this issue Oct 22, 2022 · 7 comments · Fixed by #4227
Closed
2 of 6 tasks

v2022.10.0 may cause previous "script" values in launch.json fail to execute #4223

changbowen opened this issue Oct 22, 2022 · 7 comments · Fixed by #4227
Assignees
Labels

Comments

@changbowen
Copy link

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

A configuration like below in launch.json is valid in the previous version 2022.8.5:

{
    "name": "Run PS Command",
    "type": "PowerShell",
    "request": "launch",
    "cwd": "${cwd}",
    "script": "Invoke-WebRequest www.bing.com",
}

With the latest 2022.10.0 it throws an error that says PowerShell does not support debugging this file type: 'Invoke-WebRequest www.bing.com'.

I know when run like this debugging might not work but it has been a convenient feature for quickly running something using F5 instead of going into tasks and select one to run. And it has invalidated all configurations dependent on this "feature".

Looks like it's related to changes here.

PowerShell Version

PSVersion                      5.1.19041.1682
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1682
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Visual Studio Code Version

Version: 1.72.2
Commit: d045a5eda657f4d7b676dedbfa7aab8207f8a075
Date: 2022-10-12T22:15:18.074Z (1 wk ago)
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.19044
Sandboxed: No

Extension Version

Steps to Reproduce

Add below configuration in launch.json and run:

{
    "name": "Run PS Command",
    "type": "PowerShell",
    "request": "launch",
    "cwd": "${cwd}",
    "script": "Invoke-WebRequest www.bing.com",
}

Visuals

image

Logs

No response

@changbowen changbowen added the Issue-Bug A bug to squash. label Oct 22, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Oct 22, 2022
@changbowen changbowen changed the title v2022.10.0 causing previous "script" values in launch.json fail to execute v2022.10.0 may cause previous "script" values in launch.json fail to execute Oct 22, 2022
@andyleejordan
Copy link
Member

Ah, will fix, thanks for the report.

@andyleejordan
Copy link
Member

andyleejordan commented Oct 25, 2022

Hi @changbowen! I think we just got this fixed in the PowerShell Preview for VS Code. Could you verify if this issue still reproduces using the preview extension?

@changbowen
Copy link
Author

Hi, thanks for the quick reply. I installed the preview version v2022.10.2. Doing "script": "Invoke-WebRequest www.bing.com" indeed works. But when I set script to something like C:\\Apps\\WinSCP\\WinSCP.com and args to an array of arguments, it would show the same prompt about not supporting debugging the file type WinSCP.com. This however works in v2022.8.5.

@andyleejordan
Copy link
Member

Well, that's at least "correct." The check in there is that the debugger can only run PS1 scripts, and a .com is not a PowerShell script. Thing is, I think I agree that the user should just run anything, as I'd left a TODO on just removing that logic. I don't know why it was put there in the first place, so I'm going to remove it.

@andyleejordan
Copy link
Member

andyleejordan commented Oct 26, 2022

Ok I fixed it for real this time. See #4231

@changbowen
Copy link
Author

Thanks! Is there a way I can test this?

Not having a separate dedicated ps1 file in the project for each debug action will definitely make the directory tree cleaner.
I agree that setting arbitrary text in script and not using a ps1 / psm1 file might be abusing the debugger to some extent. But IMHO it's really nice to have that flexibility and quickly execute an action by hitting F5. I know there are "tasks" but I would have to navigate through the command palette to select one and run, and I don't want to manually add (and remember) keyboard shortcuts for all the tasks. Most importantly it worked in the old versions so someone (like myself) could already be abusing it by having long scripts in launch.json.

For example here is a selection of of my ways of "debugger abuse" that used to work for sure. (Just to show my use case.. I didn't test all so some of them might still work with the latest version.)

{
    "name": "Publish",
    "type": "PowerShell",
    "request": "launch",
    "cwd": "${cwd}",
    "script": "C:\\Apps\\WinSCP\\WinSCP.com",
    "args": [
        "/command",
        "\"open scp://xxxx@xxxxxxxxxxxx/xxxx/ -privatekey=xxxxxxxxxxxxxxx"",
        "\"rm *\"",
        "\"put lib config.js index.html ./\"",
        "\"close\"",
        "\"exit\""
    ]
}
{
    "name": "Sites Status",
    "type": "PowerShell",
    "request": "launch",
    "script": "$ConfigDir = 'ConfigTEST'; . .\\Tools.ps1; Get-SitesStatus",
    "args": ["-DoNotLaunchBrowser"],
    "cwd": "${workspaceFolder}"
}
{
    "name": "Reload Modules",
    "type": "PowerShell",
    "request": "launch",
    "script": "$ConfigDir = 'ConfigPROD'; Import-Module .\\_Helpers.psm1 -Force; . .\\Tools.ps1;",
    "cwd": "${workspaceFolder}"
}
{
    "name": "Push Custom Resources",
    "type": "PowerShell",
    "request": "launch",
    "script": "clear;",
    "cwd": "${workspaceFolder}",
    "args": [
        "Copy-Item -Verbose xxxx\\xxxx.*   \\\\server\\share\\folder1\\;",
        "Copy-Item -Verbose yyyy\\xxxx.psm1   \\\\server\\share\\folder2\\;",
        ...
    ]
},
{
    "name": "Push MGMT PROD",
    "type": "PowerShell",
    "request": "launch",
    "script": "dotnet",
    "cwd": "${workspaceFolder}\\xxxxxxxx",
    "args": [
        "publish -c Release /p:PublishProfile=Properties\\PublishProfiles\\Production.pubxml;",
        "C:\\Apps\\WinSCP\\WinSCP.com /command",
        "\"open sftp://username:password@ftpserver/xxxxxxxx/inetpub/ \"",
        "\"rm xxxxxxxx.* \"",
        "\"synchronize remote .\\bin\\Release\\netcoreapp3.1\\publish \"",
        "\"exit\""
    ]
}

@andyleejordan
Copy link
Member

It'll be in the next preview release shortly!

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.

2 participants