Vscode-powershell: Debug PowerShell 5.1 Untitled Files Not Working

Created on 2 Jun 2021  路  8Comments  路  Source: PowerShell/vscode-powershell

Issue Description

Porting an issue from here that was determined to be an extension issue specifically. Had previously created this issue but it was closed prematurely.

Unless my memory is incorrect, one of the biggest advantages to VS Code over ISE was that we used to be able to set breakpoints and debug Powershell files that were untitled and not saved yet.

With this version I've noticed that no longer works, I can set a breakpoint on an untitled tab and it does not stop, it simply runs the entire script without stopping.

image

Attached Logs

Follow the instructions in the README about
capturing and sending logs.

Environment Information

Visual Studio Code

| Name | Version |
| --- | --- |
| Operating System | Windows_NT x64 10.0.19042 |
| VSCode | 1.56.0|
| PowerShell Extension Version | 2021.2.2 |

PowerShell Information

|Name|Value|
|---|---|
|PSVersion|5.1.19041.906|
|PSEdition|Desktop|
|PSCompatibleVersions|1.0 2.0 3.0 4.0 5.0 5.1.19041.906|
|BuildVersion|10.0.19041.906|
|CLRVersion|4.0.30319.42000|
|WSManStackVersion|3.0|
|PSRemotingProtocolVersion|2.3|
|SerializationVersion|1.1.0.1|

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)

|Extension|Author|Version|
|---|---|---|
|material-icon-theme|PKief|4.6.0|
|powershell|ms-vscode|2021.2.2|
|vscode-inline-values-powershell|TylerLeonhardt|0.0.5|

Area-Debugging PowerShell 5.1 Resolution-Answered

All 8 comments

Hi, please try the latest release (from yesterday) v2021.5.1. I see your comment here https://github.com/PowerShell/vscode-powershell/issues/3343#issuecomment-843671740. I cannot repro this on my Mac with PowerShell 7 and 2021.5.1.

Unfortunately I have and it still does not stop on the breakpoint. This is with VS Code version 1.56.2 now.

Can you try PowerShell 7? Just trying to narrow down the cause.

I can't install it to try it right now, and we don't use anything past 5.1 since there's no good way to reliably make sure all client machines have it. Assuming my personal machine has the same issue I can try it later today and update this issue with my findings.

As far as I know, debugging untitled files in PowerShell 5.1 is unsupported (at least, it's not working now, and hasn't worked since I started maintaining the extension based on bug reports). I would suggest using the new (currently only in Insiders) configuration setting to always prompt to save files when debugging if you're still using PowerShell 5.1:

"[powershell]": {
    "debug.saveBeforeStart": "allEditorsInActiveGroup"
}

As per #3357 we no longer prompt to save untitled files.

Okay, I could have sworn it had always worked in the past and was one of the nicer improvements over using ISE in that you could debug a quick test without having to leave junk files everywhere. If that is no longer the case and won't be continued then you may close this out,.

The prompting to save files which changed (broke imo, it never used to have that behavior) where they included that particular setting to allow for it to be changed to 'nonUntitledEditorsInActiveGroup' so that it behaved like it has for years before that maybe changed how the debugger interacts with these files, some sort of conflict perhaps? The Powershell extension expects it to be saved now but it isn't since VS Code (with that setting) doesn't prompt to do so, and simply runs it instead. That setting is in production now as well, but we can't really move off of Powershell 5.1 since it is what comes with Windows. Unfortunately there is no reliable way to ensure that thousands of endpoints all have Powershell 7 when we run scripts against them, more so without adversely affecting certain environments.

The prompting to save files which changed (broke imo, it never used to have that behavior)

I _think_ what happened was that upstream VS Code added behavior to prompt to save files, or in some way changed it such that it started happening. Later they added the configurable option nonUntitledEditorsInActiveGroup and it was recommended we enable it by default to avoid the prompting, since most users (using the extension and PowerShell 7) _don't_ need to save the untitled files, only the subset still on PowerShell 5.1. But it is certainly a user configurable option.

we can't really move off of Powershell 5.1 since it is what comes with Windows. Unfortunately there is no reliable way to ensure that thousands of endpoints all have Powershell 7 when we run scripts against them, more so without adversely affecting certain environments.

This is certainly a pain point I think the whole team would like to see addressed, as 5.1 is in development freeze (hence the existence of 6 and now 7), but we need a version of .NET Core that has a support lifecycle as long as the Windows support lifecycle in order to include PowerShell 7 on Windows by default. That's my understanding of the situation anyway.

I could have sworn it had always worked in the past and was one of the nicer improvements over using ISE in that you could debug a quick test without having to leave junk files everywhere

Windows PowerShell doesn't have the breakpoint APIs required to debug a file in memory like that. Those APIs were added in PS 7 and we added support for them in https://github.com/PowerShell/PowerShellEditorServices/pull/1119. AFAIK, prior to that we never supported untitled file debugging.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

keposet picture keposet  路  3Comments

guidooliveira picture guidooliveira  路  3Comments

MiYanni picture MiYanni  路  3Comments

rkeithhill picture rkeithhill  路  3Comments

TheDanishDynamo picture TheDanishDynamo  路  3Comments