How do I set a environment variables in VS Code? - visual-studio-code

I need to set several environment variables in Visual Studio code. Most of the instructions I've encountered are specifically for launch.json. However, I need to set these variables before the extension (project build extension) is started so it can access them.
The only way I can get the extension to see these variables is by setting them in a shell script before launching VS Code. This is unsatisfactory since the extension completely fails if you open VS code directly, or if you forget to execute the shell script.

Related

How to set environment variables when using the VSCode Cloud Code extension?

I know how to set environment variables in Cloud Run using the web console (https://cloud.google.com/run/docs/configuring/environment-variables#setting), but how can I do this locally in the emulator when using VSCode with the Cloud Code extension?
I've only seen how to do it on the initial run (https://youtu.be/EtMIEtLQNa0?t=307) but not on subsequent runs. The advanced settings window no longer shows up when I rerun the command.
UPDATE:
There's also this explanation (of the same thing) here https://cloud.google.com/code/docs/vscode/develop-service, but I think this adds the settings to launch.json(?) which gets committed to git.
I tried adding a .env file but process.env.MY_VARIABLE is undefined.
Unfortunately, even when you use the advanced settings form on the initial run, it will save the environment variables to the launch.json. Pulling in variables from a specified file other than launch.json at runtime is not currently a supported feature in Cloud Code for VS Code.

Change terminal used by Code-Runner extension in VS Code to cmd while workspace default integrated terminal is powershell?

Is there a setting in VS Code for the Code Runner extension that lets you run in a shell that's different than the workspace's default shell?
For context, my default integrated terminal is powershell. I have the code-runner.runInTerminal setting set (see, e.g., here), and whenever I run python using the extension, it creates a new "Code" powershell integrated terminal (unless one already exists), activates my selected python environment, and runs the code. However, when it tries to activate the environment, I get this popup:
So, I'd like to change the shell that Code Runner uses to cmd, BUT I want to keep using powershell as my default integrated terminal for the workspace.
Changing my workspace's default shell to cmd isn't an option, and neither is changing to a third shell like WSL. This issue indicates to me that the environment activation isn't getting fixed in powershell anytime soon. For now, I've done what the issue suggests and have just stopped Code Runner from activating a new environment in the terminals it creates (set python.terminal.activateEnvironment to false), but I'm worried now I won't be able to have Code Runner use any other python environments than the default one. What can I do?

Debugging new VS Code CLI flag in devcontainer

I've forked VSCode on Github to try to add a tiny little feature I think would be useful, which adds a new CLI flag to code, to be used inside the VSCode terminal (like code - for stdin). I added the code, wrote tests, and now I want to try out the feature.
I'm developing inside the built-in devcontainer, so I just launched an instance of VSCode from within VSCode, connected to the devcontainer via VNC and tried to use my flag inside the VSCode-OSS terminal. However, I get an error saying "Command is only available in WSL or inside a Visual Studio Code terminal"
According to server.cli.ts, this means that the env variables VSCODE_IPC_HOOK_CLI and VSCODE_CLIENT_COMMAND aren't set, but I don't know who should be setting them, or if I need to launch VSCode in a different way for debugging.
Has anyone using the VSCode DevContainer to write additional CLI flags and knows how to debug them?

How do i set Environment Variables for Debugging PowerShell in Visual Studio Code?

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?
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

How can I set non-persistent debugging parameters in Visual Studio Code?

I'm using Visual Studio Code to do some Python debugging. When debugging, I want to specify some temporary arguments to use. These are mostly just dummy values, since its for a test. I do not want the arguments checked into version control.
At the moment I'm modifying the launch.json file to add the args. However, this gets checked into version control. How can I specify arguments without adding to this file?
Normal Visual Studio IDE creates a temporary file for debug settings that doesn't get checked in. I was hoping for something similar to that for VSCode.