Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

vcpkg env doesn't preserve the VCPKG_VISUAL_STUDIO_PATH environment variable #8009

Closed
metathinker opened this issue Sep 1, 2019 · 5 comments
Assignees
Labels
category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed

Comments

@metathinker
Copy link

To see this problem in action:

  1. On a Windows computer with Visual Studio 2017, set up VCpkg following the Quick Start instructions.
  2. In a new cmd.exe command prompt, enter:
    set VCPKG_VISUAL_STUDIO_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise
    (change "Enterprise" to whatever your VS edition is)
  3. Then enter:
    ...\vcpkg.exe env

Currently, the new environment clears the VCPKG_VISUAL_STUDIO_PATH environment variable, which you can confirm by running set VCPKG_VISUAL_STUDIO_PATH. This means that if you then run ...\vcpkg.exe install some-package-name, VCpkg is not guaranteed to use the version of Visual Studio you specified.

This is especially confusing since vcpkg env has set you up so that if you directly run the Microsoft Visual C++ compiler with cl.exe, you will get MSVC v141 taken from the VS 2017 installation path. But if you run vcpkg install whatever, the package could still be built with a different MSVC toolchain!

Proposed solution:

In an ideal world, I'd like vcpkg env to preserve the value of VCPKG_VISUAL_STUDIO_PATH set in vcpkg.exe's original environment.

Describe alternatives considered:

  • Obviously, if you don't run vcpkg env then you won't have this problem. :)
    However, you'll lose the benefits of a cleaned-up PATH and so on.
  • After each time you run vcpkg env, you could remember to set VCPKG_VISUAL_STUDIO_PATH=[whatever] again. But that's something you'd have to remember - and to figure out the first time!
  • I was actually thinking of submitting a PR just to document the current behavior above in the documentation page for VCPKG_VISUAL_STUDIO_PATH. That way, people like me who are surprised by the current behavior will be warned, while people who prefer or rely on the current behavior not changing will remain happy.

Additional context:

I ran into this problem while trying to work around the fact that Microsoft C++ REST SDK does not currently build for the Universal Windows Platform ([cpu]-uwp triples) with Visual Studio 2019's MSVC v142. See #7540 ; microsoft/cpprestsdk#1227 . It was not fun to debug.

@metathinker metathinker added the category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed label Sep 1, 2019
@MVoz
Copy link
Contributor

MVoz commented Sep 12, 2019

Variables need to be prescribed in triplet

All external will be ignored

@metathinker
Copy link
Author

metathinker commented Sep 13, 2019

Variables need to be prescribed in triplet

All external will be ignored

I'm not sure what you mean? I think I misunderstand you.

Yes, it's true that the VCPKG_VISUAL_STUDIO_PATH environment variable will be overridden if the same is set in your triplet's cmake file. But you can set both. It is not that VCPKG_VISUAL_STUDIO_PATH is totally ignored as an env var.

If VCPKG_VISUAL_STUDIO_PATH was only a triplet variable, there would be no point for this request since I would just write my own triplet file as that would be the only way to change compiler version. But it can be both in environment or in triplet.cmake, so I think the request at least makes sense.

Or maybe you intend to suggest I should write my own triplet?

@MVoz
Copy link
Contributor

MVoz commented Sep 13, 2019

vcpkg/triplet/x64-windows.cmake <<-- That's the triplet. Prescribe variables there

Read the documentation if you're really interested in understanding

@metathinker
Copy link
Author

metathinker commented Sep 13, 2019 via email

@MVoz
Copy link
Contributor

MVoz commented Sep 13, 2019

https://github.com/microsoft/vcpkg/blob/master/docs/users/triplets.md#vcpkg_visual_studio_path

set(VCPKG_VISUAL_STUDIO_PATH "C:\\Program Files (x86)\\Microsoft Visual Studio\\Preview\\Community")

The Visual Studio 2017 platform toolset is v141.

set(VCPKG_PLATFORM_TOOLSET v141)

auto default_vs_path = System::get_environment_variable("VCPKG_VISUAL_STUDIO_PATH").value_or("");

ENV SYSTEM, not USER ENV

need more?

@PhoebeHui PhoebeHui assigned cbezault and unassigned PhoebeHui Sep 18, 2019
@cbezault cbezault assigned ras0219-msft and unassigned cbezault Oct 2, 2019
@microsoft microsoft locked and limited conversation to collaborators Jul 30, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed
Projects
None yet
Development

No branches or pull requests

5 participants