Vscode-cpptools: [MSVC]How to set environment variables after opening VSCode

Created on 31 Aug 2019  路  8Comments  路  Source: microsoft/vscode-cpptools

Type: Debugger

Describe the bug

To Reproduce

Additional context

  • I looked at Developer Command Prompt and found that it was actually setting the environment variables for the current workspace. For example, these variables are set by the vcvarsall.bat batch file.
  • This was not a particularly troublesome issue. But when you have multiple versions of visual studio installed on your computer, things start to get into trouble. Every time you open a project, you need to run the corresponding version of the command line tool, which is very troublesome. If you don't do this, you won't be able to compile, suggesting that you can't find MSBuild (and I don't know if there are any other hidden dangers).
  • Is there any way to import these configurations into the environment variables of VSCode, so that you don't need to start the command line tool and cd workspace run code . with vsCode. Or is there any way to run the load environment variable when vsCode starts?
  • I am using multiple versions of vistual studio now. I hope that VSCode can compile them without having to run the command line tool to load the VC environment beforehand. I feel that this is not elegant enough. If you run vscode directly and then load the VC environment (for example by configuring the .json file), this will be very comfortable.
Feature Request Language Service builtasks help wanted

Most helpful comment

I am experiencing a similar issue where I am using the QNX compiler, which requires %QNX_HOST% to be set. For our environment variables we are using activate.bat coming from conan.

It is necessary to have QNX_HOST in the environment. Otherwise the gcc compiler cannot be queried for include paths.

It would be nice if I can set this setting in my c_cpp_properties.json in the workspace.

As a workaround I run activate.bat and then start vs-code in a similar fashion as you do with vcvarsall.

All 8 comments

I agree. Theoretically we could run the VcDevCmd.bat (auto-find and/or setting) and add the results to the process.env.

Expectantly sir

I am experiencing a similar issue where I am using the QNX compiler, which requires %QNX_HOST% to be set. For our environment variables we are using activate.bat coming from conan.

It is necessary to have QNX_HOST in the environment. Otherwise the gcc compiler cannot be queried for include paths.

It would be nice if I can set this setting in my c_cpp_properties.json in the workspace.

As a workaround I run activate.bat and then start vs-code in a similar fashion as you do with vcvarsall.

Look forward together

Unfortunately, we can't change the environment after you launch VS Code. We don't have permission to do that. You do have an opportunity to run a script as part of your tasks.json command, but those variables won't exist and be available to our extension. This would need to be a feature request on the VS Code team if you want to modify the environment after launching the editor.

Unless I'm misunderstanding, that's now on the draft iteration plan for March.

Should this issue be renamed and reopened (or a new one created) for when that lands to add @sean-mcmanus' suggestion?

@SuperWig What's on the draft iteration plan for March? You mean for VS Code? I don't see any related issue. Can you add a link to that?

What's on the draft iteration plan for March? You mean for VS Code?

@sean-mcmanus Yes for VS Code, "Allow extensions to customize the environment of terminal processes" is in the iteration plan for March.

There wasn't a linked issue when I saw it yesterday but it's there now as https://github.com/microsoft/vscode/issues/46696

Was this page helpful?
0 / 5 - 0 ratings