vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

`VCPKG_ROOT` is not set when using `Set Visual Studio Developer Environment`

Open maxime-modulopi opened this issue 2 months ago • 6 comments

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 avatar Dec 04 '25 10:12 maxime-modulopi

@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 avatar Dec 04 '25 20:12 sean-mcmanus

@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 avatar Dec 05 '25 10:12 maxime-modulopi

@maxime-modulopi Does running the "CMake: Delete Cache and Reconfigure" command fix it?

sean-mcmanus avatar Dec 05 '25 19:12 sean-mcmanus

@sean-mcmanus No, this issue happen even with a fresh CMake cache (by entirely deleting the build directory or with this command)

maxime-modulopi avatar Dec 08 '25 09:12 maxime-modulopi

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".

maxime-modulopi avatar Dec 08 '25 09:12 maxime-modulopi

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:

  1. Create a new project and add the code.
  2. Launch the VS Command Prompt, go to the project folder using 'cd', and enter 'code .' to open VS Code.
  3. Configure the project and observe the result. It shows 'VCPKG_ROOT: "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\vcpkg"'.
  4. Close VS code, restart it by clicking the VS Code icon.
  5. Configure the project and observe the result. It shows 'VCPKG_ROOT: ""'.

Details please see following video: Image

FYI: @gcampbell-msft

yanghhhhhhh avatar Dec 09 '25 06:12 yanghhhhhhh

Configure is working fine now, thank you!

maxime-modulopi avatar Dec 15 '25 09:12 maxime-modulopi