Skip to content

[MSVC]How to set environment variables after opening VSCode #4178

Closed

Description

@swq123459

Type: Debugger

Describe the bug

  • OS and Version:win10 1903 x64
  • VS Code Version:1.37.1
  • C/C++ Extension Version:0.25.0

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.

Activity

  1. sean-mcmanus commented on Sep 3, 2019

    @sean-mcmanus
    Contributor

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

  2. swq123459 commented on Sep 4, 2019

    @swq123459
    Author

    Expectantly sir

  3. giantmustache commented on Sep 20, 2019

    @giantmustache

    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.

  4. swq123459 commented on Sep 20, 2019

    @swq123459
    Author

    Look forward together

  5. bobbrow commented on Mar 5, 2020

    @bobbrow
    Contributor

    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.

  6. SuperWig commented on Mar 9, 2020

    @SuperWig

    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 (@sean-mcmanus)' suggestion?

  7. sean-mcmanus commented on Mar 10, 2020

    @sean-mcmanus
    Contributor

    Daniel Marshall (@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?

  8. SuperWig commented on Mar 10, 2020

    @SuperWig

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

    Sean McManus (@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 microsoft/vscode#46696

  9. locked and limited conversation to collaborators on Oct 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions