Skip to content

Easy way Configure debug on specific powershell version #1302

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
manytwo opened this issue Apr 27, 2018 · 5 comments
Closed

Easy way Configure debug on specific powershell version #1302

manytwo opened this issue Apr 27, 2018 · 5 comments
Assignees

Comments

@manytwo
Copy link

manytwo commented Apr 27, 2018

Is there a simple way to start a debug session to an older version of powershell?

The launch.json file can't handle powershell command line arguments, it can be an easy way to add some debug options.

I m not very familiar with advanced vscode debug configurations, How can this be done rigth now?

@rkeithhill
Copy link
Contributor

The launch.json file can't handle powershell command line arguments

Are you referring to the script/command that is to be debugged? If so, you can pass arguments to that command:

        {
            "type": "PowerShell",
            "request": "launch",
            "name": "PowerShell Launch DebugTest.ps1",
            "script": "${workspaceRoot}/DebugTest.ps1",
            "args": ["-Count 55 -DelayMilliseconds 250"],
            "cwd": "${workspaceRoot}"
        },

If you are referring to passing commands to PowerShell.exe, then no it doesn't do that. One issue, is that once you start VSCode and open a PowerShell file, the PowerShell Integrated Console is started to handle both language service requests (search symbols, script analysis, etc) an debug service requests. That is, before you even start debugging, PowerShell is already running. You're debugging in the PowerShell Integrated Console context.

You can specify other versions of PowerShell Core via the PowerShell session menu:
image
However, if you are referring to different versions of Windows PowerShell, you pretty much only have one version installed by default - 3, 4, 5 or 5.1. The latest version overwrites previous versions. While true that you can optionally enable v2, v2 is deprecated. I'm not even sure VSCode supports v2.

@manytwo
Copy link
Author

manytwo commented Apr 30, 2018

I mean Pass arguments to powershell.exe .
Goal is simple: Debug powershell with -Version 2 parameter. Even if powershell V2 is deprecated, some scripts should work even on windows server 2003 in my case.

That is, before you even start debugging, PowerShell is already running. You're debugging in the PowerShell Integrated Console context.

Launch.json provide a sample to start in a new temporary terminal. I was looking how to send arguments to powershell.exe at this launch.

       {
            "type": "PowerShell",
            "request": "launch",
            "name": "PowerShell Launch Current File in Temporary Console",
            "script": "${file}",
            "args": [],
            "cwd": "${file}",
            "createTemporaryIntegratedConsole": true
        },

More powershell will be updated, more we will need an easy way to switch powershell versions for testing.
We should be able to switch PSScriptAnalyser service for a target version of powershell easily for example (I know you can already attach custom PSScriptAnalyzer). It can be usefull to see directly in VS code if your script is backward compatible.

@rjmholt
Copy link
Contributor

rjmholt commented May 2, 2018

Hi @manytwo, thanks for the question. Like @rkeithhill says, there are a couple of obstacles:

  • We don't support PowerShell v2, meaning that we can't execute a script against PowerShell v2, regardless of whether it also works in v3. We can execute a script written for v2 in a later PowerShell version, but it will only tell you how that script performs in that later version of PowerShell.
  • The EditorServices debugging service is started when you start the extension, and that debugging service uses the hosted PowerShell API that we get from the PowerShell executable that we start editor services with. So there's no way to pass a parameter in, because PowerShell is already started and editor services is running on top of it.

@rkeithhill actually implemented way to pick what PowerShell executable you want to run on, so you can run on any PowerShell executable you have access to. But it is architecturally infeasible for us to switch PowerShell versions at runtime. In fact, just supporting as many as we do at startup is a serious challenge.

But the version that the VSCode PowerShell extension supports at runtime is the version of the executable you start it with, because it reaches down into its hosting PowerShell executable to run all of its services.

I believe PSScriptAnalyzer has compatibility analysis on their list (again, @rkeithhill has an issue on this: PowerShell/PSScriptAnalyzer#127). It's also very much open source, so I'm sure they would love to accept any contributions you can make.

More powershell will be updated, more we will need an easy way to switch powershell versions for testing.

You're right, and that is being worked on, but I will add "the more users will need to update".

@rjmholt
Copy link
Contributor

rjmholt commented May 4, 2018

I'm closing this, since the intended resolution for this is being worked on in PSSA.

@colemickens
Copy link

What is PSSA? How can I use the PowerShell Core preview as the debugger?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants