-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
Describe the bug
If you set the VCPKG_LOAD_VCVARS_ENV
to false, then vcpkg will still launch a VS Command prompt to get the vcvars environment.
Environment
- OS: Windows
To Reproduce
Steps to reproduce the behavior:
- Create a custom triplet with
set(VCPKG_LOAD_VCVARS_ENV OFF)
. For example:
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_LOAD_VCVARS_ENV OFF)
- Run a build with no compiler on the
PATH
, noLIB
env var set, etc.
Expected behavior
vcpkg/CMake complains that it can't find a compiler.
Additional context
The bug occurs when vcpkg uses the value load_vcvars_env
which is set by VCPKG_LOAD_VCVARS_ENV
:
bool PreBuildInfo::using_vcvars() const
{
return (!external_toolchain_file.has_value() || load_vcvars_env) &&
(cmake_system_name.empty() || cmake_system_name == "WindowsStore");
}
If there is no external toolchain file (VCPKG_CHAINLOAD_TOOLCHAIN_FILE
is not set) then !external_toolchain_file.has_value()
is true
and so the value of load_vcvars_env
is ignored, thus VCPKG_LOAD_VCVARS_ENV
cannot be used to disable vcvargs loading.
It could, however, be used to re-enable vcvars loading if VCPKG_CHAINLOAD_TOOLCHAIN_FILE
was set - but that's not what the documentation indicates it does: "Determines whether vcpkg will search for and use an instance of Visual Studio as part of the triplet environment."
For anyone who came across this issue looking for a way to disable vcvars loading WITHOUT using a custom toolchain file, the workaround is to add set(VCPKG_CMAKE_SYSTEM_NAME Windows)
to your triplet.
It should be noted that changing the behavior now would be a breaking change, which I'm not sure how vcpkg handles.
Activity
jimwang118 commentedon Oct 15, 2024
Following the steps you provided, I was unable to reproduce this issue.

dpaoliello commentedon Oct 15, 2024
I think you did reproduce the issue: with
VCPKG_LOAD_VCVARS_ENV
set to off, your build was still finding the MSVC compiler - it shouldn't be able to do that.jimwang118 commentedon Oct 16, 2024
I understand what you mean. When I only use load_vcvars_env to determine whether to use vcvars, it prompts that the cxx compiler cannot be found.
github-actions commentedon Apr 14, 2025
This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.
dpaoliello commentedon Apr 21, 2025
This is a new comment to stop the bot from closing this, since it isn't smart enough to see that there is an open PR to fix the issue...