4

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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I don't think that's the same issue. OP wants to add env to launch.json (as is possible with NodeJS) and that link is describing the environment of the powershell terminal.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.