To modify your Conan profile to detect and use the full path to the MSVC compiler, you need to capture the third return value from the detect_msvc_compiler() function, which typically contains the compiler path. Here's how to do it:
✅ Step 1: Capture the Compiler Path
In your Conan profile Jinja2 template, update the line that calls detect_msvc_compiler() to capture all three return values:
{% set compiler, version, compiler_path = detect_api.detect_msvc_compiler() %}
This assumes detect_msvc_compiler() returns a tuple like:
("msvc", "19.29", "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64")
Note: The exact format of the return value may vary depending on your Conan version and Visual Studio installation. If compiler_path is not the full path to cl.exe, you may need to construct it manually using subdirectories like bin or Hostx64.
✅ Step 2: Set Environment Variable or Pass to Build System
Once you have the compiler_path, you can expose it to your build system in one of the following ways:
Option A: Set an Environment Variable in the Profile
Add an [env] section to your Conan profile to expose the compiler path to the build environment:
[env]
MSVC_COMPILER_PATH={{ compiler_path }}
This will set the MSVC_COMPILER_PATH environment variable to the detected compiler path during the Conan install or build process.
Option B: Pass to CMake via Conan Settings (if applicable)
If you're using CMake, you can optionally set the CMAKE_CXX_COMPILER variable via Conan settings or environment variables:
[settings]
os=Windows
arch=x86_64
compiler=msvc
compiler.version=19.29
compiler.runtime=dynamic
compiler.toolset=host=x64
[env]
CMAKE_CXX_COMPILER={{ compiler_path }}/cl.exe
Note: MSVC typically requires the environment to be set up via vcvarsall.bat, so setting CMAKE_CXX_COMPILER directly may not always work unless you're using a custom toolchain or generator.
✅ Step 3: Use the Path in Your Build or Package Recipe
In your or , you can now access the environment variable or use it in your build logic: