Skip to content

Enable setting the VS dev environment without running from Dev Command Prompt #13571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

bobbrow
Copy link
Member

@bobbrow bobbrow commented Apr 30, 2025

This change removes the requirement of running VS Code from a Developer Command Prompt in order to build with the Visual Studio C++ compiler on Windows.

Two commands are added:

  • Set Visual Studio Developer Environment - Starts the process of picking the MSVC toolset that will be used to compile. This environment will be added to any new terminals launched from this session of VS Code. It will also be automatically applied for the Build and Debug feature. Note that the environment changes only apply to the current workspace. The command will need to be run on every workspace that needs the environment.
  • Clear Visual Studio Developer Environment - Removes the MSVC toolset environment.

One setting is added:

  • C_Cpp.persistDevEnvironment - This controls whether the developer environment is automatically applied the next time the workspace is opened.

Walkthrough updates

The walkthrough is updated with a button to run the command and the instructions include the command as an alternative option to running VS Code from the Developer Command Prompt:
image

Play button updates

The Play button for Build and Debug Active File incorporates this command in the workflow if the developer environment is not detected. This should make the experience seamless going forward.
image

Terminal updates

When the command is run, any existing terminals will show a message prompting you to relaunch them so that the environment will apply to them.
image

Telemetry

Telemetry is added to track where the command was invoked.

@bobbrow bobbrow marked this pull request as ready for review April 30, 2025 23:09
@bobbrow bobbrow requested a review from a team as a code owner April 30, 2025 23:09
Copy link
Contributor

@sean-mcmanus sean-mcmanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be fixed?

image

Copy link
Contributor

@sean-mcmanus sean-mcmanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should just silently cancel instead of showing an error.

image

I think an error might be okay if it was an actual error occurrence (and without it the user may not know it failed) but not a user cancellation though (via not selecting an option in the dropdowns).

We don't share an error popup in other cancellation cases.

Same as when the user hits the "Cancel" button:

image

Copy link
Contributor

@sean-mcmanus sean-mcmanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the command name?

image

It's possible the command may not have been invoked from the developer command prompt or in a way the user is 100% sure what command is run, such as via a keyboard shortcut.

Umm...unless VS Code itself is showing that message, I haven't checked yet.

Copy link
Contributor

@sean-mcmanus sean-mcmanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we align the setting name more with CMake Tools?

image

i.e. C_Cpp.persistVsDeveloperEnvironment ?

i.e. "VsDeveloper" seems preferable to "Dev" since it's more explicit that it applies to Visual Studio. And "Dev" seems informal for a setting name.

sean-mcmanus

This comment was marked as resolved.

sean-mcmanus

This comment was marked as resolved.

Copy link
Contributor

@sean-mcmanus sean-mcmanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If VS Code is already launched from a particular VS developer command prompt, then the Set VS Developer Environment command is still available and runnable, but confusingly has no effect with no warning that it's not actually used, i.e. it just uses the original environment. Can that be fixed somehow or give a warning? Or is it supposed to work and switch to the newly selected developer environment?

@bobbrow
Copy link
Member Author

bobbrow commented May 6, 2025

If VS Code is already launched from a particular VS developer command prompt, then the Set VS Developer Environment command is still available and runnable, but confusingly has no effect with no warning that it's not actually used, i.e. it just uses the original environment. Can that be fixed somehow or give a warning? Or is it supposed to work and switch to the newly selected developer environment?

I would expect it to override the inherited environment. Does it not work for you? It worked for me.

@sean-mcmanus

This comment was marked as resolved.

sean-mcmanus

This comment was marked as resolved.

@bobbrow
Copy link
Member Author

bobbrow commented May 7, 2025

Ok, I did notice an oddity that I will need to debug. Something wrong did happen when the dev environment is already set and it does appear to fail to update all of the required variables.
image

image

I originally only checked that the compiler was coming from the correct path, but you are right that the environment is not correct. (e.g. VSINSTALLDIR is wrong in that screenshot)

@bobbrow
Copy link
Member Author

bobbrow commented May 7, 2025

I have a fix for the "run from the developer command prompt" scenario in the node module. I just need to wait for it to show up in CFS so I can consume it.

bobbrow/node-vcvarsall@5556a28

@bobbrow
Copy link
Member Author

bobbrow commented May 7, 2025

The latest push should address the remaining issues.

@sean-mcmanus sean-mcmanus self-requested a review May 7, 2025 21:29
sean-mcmanus

This comment was marked as resolved.

@bobbrow
Copy link
Member Author

bobbrow commented May 7, 2025

The Apply Developer Environment popup doesn't appear if the VS install for the persisted environment is changed (removed or the version changes). It just fails to find the cl.exe.

[image]
It seems like user could be confused why it stopped working and they may not know they need to run the Clear/Set again. Are we able to detect that condition and do the Clear ourselves?

Are you talking about when you upgrade VS and get a new toolset version for cl.exe? We can probably check for that.

@sean-mcmanus
Copy link
Contributor

Are you talking about when you upgrade VS and get a new toolset version for cl.exe? We can probably check for that.

Yes upgrade or uninstall, e.g. uninstall Preview but you have non-Preview still then ideally the Apply option would appear for the non-Preview that is still installed.

@sean-mcmanus sean-mcmanus self-requested a review May 8, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Pull Request
3 participants