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.

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