`VCPKG_ROOT` is not set when using `Set Visual Studio Developer Environment`
Extension version: 1.29.2 OS: Windows 11 x64
In a x64 Native Tools Command Prompt for VS 2022 terminal, VCPKG_ROOT is set to the vcpkg instance provided as part of Visual Studio.
When setting the Visual Studio toolchain via the Set Visual Studio Developer Environment command instead of launching vscode from this terminal, this env variable is missing even though both methods should be equivalent.
This breaks CMake configurations that rely on this env variable for vcpkg.
@maxime-modulopi I do not repro the issue. After setting the developer environment, I create a new power shell terminal in VS Code and run Get-ChildItem Env: and I see the VCPKG_ROOT environment variable (pre-existing terminals won't have the new environment variables added and show a warning icon about that). Do you get the same results or what exactly do you mean by "breaks CMake configurations", i.e. how can I repro that?
@sean-mcmanus It happens when running the CMake: Configure command from the CMake Tools extension (for context, I use $ENV{VCPKG_ROOT} in my CMakeLists.txt).
It seems to be a problem with this command specifically as VCPKG_ROOT is indeed correctly set in the Terminal window.
@maxime-modulopi Does running the "CMake: Delete Cache and Reconfigure" command fix it?
@sean-mcmanus No, this issue happen even with a fresh CMake cache (by entirely deleting the build directory or with this command)
Here are CMake files that can reproduce the issue:
CMakeLists.txt
cmake_minimum_required(VERSION 3.28)
project(Test)
message("VCPKG_ROOT: \"$ENV{VCPKG_ROOT}\"")
CMakePresets.json
{
"version": 3,
"configurePresets": [
{
"name": "Debug",
"binaryDir": "${sourceDir}/build/${presetName}",
"generator": "Ninja",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
}
}
]
}
When configuring CMake with these files, CMake prints [cmake] VCPKG_ROOT: "" in the vscode OUTPUT tab.
Executing the same steps in a vscode instance launched from a VS terminal prints [cmake] VCPKG_ROOT: "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg".
Hi @maxime-modulopi , thanks for reporting issue here! We can reproduce this issue on Visual Studio Code v1.106.3 + CMake Tools v1.21.36 release version.
Repro Steps:
- Create a new project and add the code.
- Launch the VS Command Prompt, go to the project folder using 'cd', and enter 'code .' to open VS Code.
- Configure the project and observe the result. It shows 'VCPKG_ROOT: "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\vcpkg"'.
- Close VS code, restart it by clicking the VS Code icon.
- Configure the project and observe the result. It shows 'VCPKG_ROOT: ""'.
Details please see following video:
FYI: @gcampbell-msft
Configure is working fine now, thank you!