Reputation: 318
I need to debug a PowerShell script that uses several environment variables. For practical reasons, I need to be able to change the variables on the fly, and it would be painful to have to restart Visual Studio Code every time I want to change the variables.
In Visual Studio, when debugging C++ code it is easy to set environment variables by configuring the debug settings of your Start Up Project.
I've also found another question that was answered, but it seems to apply specifically to how to configure Environment variables for debugging node.js projects. (How do I add environment variables to launch.json in VSCode)
Is there not a global way to configure environment variables for the Visual Studio Code Debugger?
Upvotes: 4
Views: 4379
Reputation: 14277
Surprisingly it's not possible for PowerShell. The workaround is to add a script which does it and then runs your powershell for debugging. Depending on your OS (linux, osx, windows) you add the corresponding block:
"windows": {
"script": "$env:SOMEVAR=\"foo\"; ./myscript.ps1"
},
Alternatively you could create a .env
file and have your script read that.
Upvotes: 0
Reputation: 318
It's not currently possible. See this open issue for the Powershell Plugin for Visual Studio Code: https://github.com/PowerShell/vscode-powershell/issues/1472
Upvotes: 1