Vscode-powershell: Would like a "Debug" configuration to run in external Posh Console, passing params.

Created on 11 Nov 2019  Â·  11Comments  Â·  Source: PowerShell/vscode-powershell

PowerGui, rest its soul, had the option to run the script in an external window. I would not expect this to respect breakpoints and whatnot... I just want to be able to run the script in the external window without having to copy/paste or manually run the script.
I have looked at the debug configurations in launch.json, but I can't figure out how to make the script execute in an external posh console.

While VSCode and the PowerShell add-in are an awesome pair, sometimes I need to see what the script will be like when it runs in the real world. This solution would ease that kind of testing.

Proposed technical implementation details (optional)

I think the simplest solution would likely be to support a new launch.json configuration that would pop up an external console window, passing the script and command line arguments. This would require no additional UI elements and could be easily communicated.

Area-Configuration Area-Debugging Issue-Enhancement Up-for-Grabs

Most helpful comment

100% this should be included.
I think it's very easy to forget that most of the time spent by experienced PowerShell scripters is running scripts, rather than debugging.

I use the following launch options as a work around:

    {
        "type": "PowerShell",
        "request": "launch",
        "name": "Run in External PowerShell Window - v5 - Elevated",
        "script": "Start-Process",
        "args": [
            "-FilePath ($Env:SystemRoot + '\\system32\\WindowsPowerShell\\v1.0\\powershell.exe')",
            "-Verb Runas",
            "-Argumentlist '-NoExit -NoProfile -ExecutionPolicy Bypass -File \"${file}\"'"
        ],
        "cwd": "${file}"
    },
    {
        "type": "PowerShell",
        "request": "launch",
        "name": "Run in External PowerShell Window - v5",
        "script": "Start-Process",
        "args": [
            "-FilePath ($Env:SystemRoot + '\\system32\\WindowsPowerShell\\v1.0\\powershell.exe')",
            "-Argumentlist '-NoExit -NoProfile -ExecutionPolicy Bypass -File \"${file}\"'"
        ],
        "cwd": "${file}"
    }

However, I really, really hope that this issue is not closed; because it would be great to be able to debug the new window as if it was the integrated console if required.

All 11 comments

@KevinLeeBuchan thanks for opening this issue--not totally sure if this is currently possible, but it may be possible today by configuring your launch.json, using the PowerShell attach to process configuartion and the "preLaunchTask"

    "version": "0.2.0",
    "configurations": [
        {
            "name": "PowerShell Attach to Host Process",
            "type": "PowerShell",
            "request": "attach",
            "runspaceId": 1,
            "preLaunchTask": "[call to open powershell in external window with custom pipename]",
            "customPipeName": "pipename"
        }

Currently we don't have any plans to ship this with the extension but if you get this working please let us know and we'd be happy to help you open a PR--for now I will mark this as up for grabs...thanks again for raising this! Also we are more than happy to help if you have other ideas to make this possible!

This may be helpful documentation https://code.visualstudio.com/Docs/editor/tasks#_custom-tasks

100% this should be included.
I think it's very easy to forget that most of the time spent by experienced PowerShell scripters is running scripts, rather than debugging.

I use the following launch options as a work around:

    {
        "type": "PowerShell",
        "request": "launch",
        "name": "Run in External PowerShell Window - v5 - Elevated",
        "script": "Start-Process",
        "args": [
            "-FilePath ($Env:SystemRoot + '\\system32\\WindowsPowerShell\\v1.0\\powershell.exe')",
            "-Verb Runas",
            "-Argumentlist '-NoExit -NoProfile -ExecutionPolicy Bypass -File \"${file}\"'"
        ],
        "cwd": "${file}"
    },
    {
        "type": "PowerShell",
        "request": "launch",
        "name": "Run in External PowerShell Window - v5",
        "script": "Start-Process",
        "args": [
            "-FilePath ($Env:SystemRoot + '\\system32\\WindowsPowerShell\\v1.0\\powershell.exe')",
            "-Argumentlist '-NoExit -NoProfile -ExecutionPolicy Bypass -File \"${file}\"'"
        ],
        "cwd": "${file}"
    }

However, I really, really hope that this issue is not closed; because it would be great to be able to debug the new window as if it was the integrated console if required.

@JamesLear92 thanks for providing your feedback and a workaround. I wonder if we could take advantage of custom pipe name (added in PowerShell 6) and us "attach" as the request type to accomplish this and still get the debugging experience in VSCode?

@SydneyhSmith
I'll take another look today if I get a moment
I haven't had much luck with the "attach" launchers in the past (I might be using them incorrectly); but they don't seem to execute the script in the attached process.

Once drawback of the launch options I posted before is that they cannot launch unsaved files which is a bit of a shame

Currently, the integrated terminal, while awesome, doesn't have support for "Write-Progress", so popping up a running script in an external console is very helpful. Debugging is secondary, for me, because the experience is so nice within VSCode.

I can make do with the solution @JamesLear92 showed. Having VSCode support for other features you can currently only get through the console would help even more.

@KevinLeeBuchan

Can you give this a go in the PowerShell Preview extension? It has a ton of fixes in it and Write-Progress should work there.

@SydneyhSmith
I thought your custompipename was a neat idea so I gave it another go. Unfortunately it's not working for me. The pretask opens the script in a new window, and uses the filename as the pipename and it opens, but the launch does not then attach.
I think also breakpoints won't work like this.

What we really need is the ability to launch spool up a new intergrated terminal as a new window (not physically attached to VSCode main window).

But I think this is likely a VSCode limitation.

Looking forward to testing it!


Sent from my iPhone, probably via dictation. Please excuse any typos.

On Nov 22, 2019, at 10:55 AM, Tyler James Leonhardt notifications@github.com wrote:


@KevinLeeBuchan

Can you give this a go in the PowerShell Preview extension? It has a ton of fixes in it and Write-Progress should work there.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Any ideas what the next steps should be? I couldn't get this to work back in November and but I'd love this functionality

@JamesLear92 since it is possible to launch and attach to another PowerShell process (Azure Functions as an example) there is no obvious reason why this wouldnt be possible...unfortunately we also havent had time to look closely at this (and likely wont in the short term) so we have no update on the next steps

Was this page helpful?
0 / 5 - 0 ratings