Cannot set toolset when configuring with the Visual Studio 2022 generator.

I have installed on my machine Visual Studio 2022 17.9 with the MSVC toolsets 14.36, 14.38 and 14.39. I created with Visual Studio a new “CMake project” and after configuring it with cmake -S . -B build -G "Visual Studio 17 2022" I noticed that CMake is choosing MSVC 14.36; the oldest one.

I tried to manually choose the latest toolset by passing -T v143,version=14.39 but every time it fails with No CMAKE_C/CXX_COMPILER could be found.. I tried the same while under the Visual Studio developer Powershell (both with and without specifying -vcvars_ver=14.39) but the result has been either failure to find the compiler, or finding 14.36.

Am I doing something wrong? Thanks.

1 Like

@brad.king Is this the Visual Studio toolchain bug?

VS 17’s v143 minor toolsets 14.36 through 14.39 cannot be used by -T version= due to a bug in VS. See VS Developer Community feedback item 10385615 and CMake Issue 25192.

In the Visual Studio Installer’s section for VS 17.9, look under Desktop development with C++ and make sure the MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest) component is installed. If installed, CMake should choose that by default.

I gave it another try and it printed The CXX compiler identification is MSVC 19.38.33135.0. The following components are installed:

image

Please look for a file

C:/Program Files/Microsoft Visual Studio/2022/*/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt

where * depends on the VS edition (Preview, Community, Professional, or Enterprise). What does it contain?

14.39.33519

BTW there is also a Microsoft.VCToolsVersion.v143.default.txt file that contains 14.38.33130.

If those two files disagree something may be wrong with the VS installation. Try removing the “Latest” component I mentioned above and then installing it again.

I reinstalled the “Latest” component and installed it again. The files are still different.

I am going to reinstall Visual Studio…

On reinstall, select the “Latest” toolchain but don’t install any of the minor toolchains yet. Let’s make sure the basic usage works first.

Sorry to bother that old post.
However, I receive nearly the same error with Visual Studio 2022 17.11 Preview2 with the latest build tools of v143. This looks like the VCTargetPath is incorrect, and due to that CompilerIdCXX.proj does not compile at all. Even more, somehow that project was generate with <Import Project="C:/Program Files/Microsoft Visual Studio/2022/Preview\VC\Auxiliary\Build\14.41.33923\Microsoft.VCToolsVersion.14.41.33923.props" />

While I do not have that file, and just have C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\Build folder filled with .props items

Running CMake 3.30.0-rc3 with -G "Visual Studio 17 2022" and no -T argument works fine for VS 17.11p2 for me. Adding -T 14.41 gets an error, which I’m addressing in CMake MR 9622.

1 Like

I still have this kind of problem. Let me use the simplest scenario to demonstrate the problem -

  1. My environment: Visual Studio 2022 17.10 with MSVC 14.40.33078 (only 1 MSVC Toolset installed) + CMake 3.31.4
  2. Write a super simple helloWorld.cpp and CMakelist.txt for demo purpose
  3. Open CMakeGUI to config the project, the VCTargetsPath.vcxproj generated is as
  <PropertyGroup Label="Configuration">
    <ConfigurationType>Utility</ConfigurationType>
    <CharacterSet>MultiByte</CharacterSet>
    <PlatformToolset>v143</PlatformToolset>
  </PropertyGroup>

I expect it selects MSVC 14.40 (the latest one) as toolset but t looks for MSVC 14,36 then and error out -
“error MSB8070: Cannot find MSVC toolset version ‘14.36.32532’: the folder 'C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532' does not exist. Please make sure MSVC toolset version ‘14.36.32532’ is installed or choose another toolset version. [D:\Test\MSVC144\CMakeFiles\3.31.4\VCTargetsPath.vcxproj]”

  1. I tried to add -T option, neither formats “version=14.40.33807”, “version=14.40” or “-T 14.40” work. These options seem changing platform toolset only.
  2. Changing Microsoft *.prop as suggested above is not an option for me.
  3. It is not an option for me in batch build environment to modify the vcxproj by adding
"<VCToolsVersion>14.40.33807</VCToolsVersion>"  

My question is - how can I instrument CMake to select the correct MSVC Toolset? Or we have to rely on Microsoft Visual Studio to select the latest MSVC toolset in future release?

I believe the correct format for -T would be -T v143,version=14.40.33807. Does that work for you?

NO, as I tried " -T v143,version=14.40.33807", the issue is not fixed.

It works fine for me:

>cmake -B build -G "Visual Studio 17 2022" -T v143,version=14.40.33807
...
-- The C compiler identification is MSVC 19.40.33818.0
...
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/cl.exe - skipped
...

The resulting .vcxproj files contain both <PlatformToolset>v143</PlatformToolset> and:

<Import Project="C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Auxiliary/Build/14.40.17.10/Microsoft.VCToolsVersion.14.40.17.10.props" />

@XJPan try installing the “latest” toolset in addition to the versioned toolset.