Just wasted 2 hours trying to fix powershell debugging in VS Code ....
.... until I remembered that we implemented Constrained Mode a few weeks ago ....
Seems like debugging is not compatible with constrained mode!
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to debug my PowerShell 7 script in Visual Studio Code 1.71.0. I have extension ms-vscode.powershell Version: 2022.8.5 installed. I don't understand why it doesn't come ready to debug PS1 files out of the box, but it doesn't. When I tried it, I was told I had to create a launch.json. Wouldn't that be specified by the extension?
So based on Using Visual Studio Code for PowerShell Development - PowerShell | Microsoft Learn, I added the code below to my settings.json file:
{
"version": "0.2.0",
"configurations": [
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Launch (current file)",
"script": "${file}",
"args": [],
"cwd": "${file}"
},
{
"type": "PowerShell",
"request": "attach",
"name": "PowerShell Attach to Host Process",
"processId": "${command.PickPSHostProcess}",
"runspaceId": 1
},
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Interactive Session",
"cwd": "${workspaceRoot}"
}
]
}
Now I can start debugging? Right? Wrong. It runs my script when I press F5, but when I try to run code declared in that script, my code runs without being debugged. Breakpoints aren't hit.
How can I fix this problem?
Just wasted 2 hours trying to fix powershell debugging in VS Code ....
.... until I remembered that we implemented Constrained Mode a few weeks ago ....
Seems like debugging is not compatible with constrained mode!
Hello there,
This can happen if your PackageManagement module isn't up to date, VSCode picks up on that, displays a pop-up on the lower right of the screen asking if you want to update and doesn't consider Powershell started until it's dismissed.
Installing the latest version of package management and then restarting either the PowerShell session or VSCode resolved the issue for most of the users who faced the similar issues.
You also may need to make sure that you don't have this Session exited warning. If you do, click "Restart Current Session", then try pressing F5 again.
I hope this information helps. If you have any questions please let me know and I will be glad to help you out.
---------------------------------------------------------------------------------------------------------------------------------------
--If the reply is helpful, please Upvote and Accept it as an answer--
Is VS Code starting the right version of PowerShell in this session?