I am trying to use cmake 3.23.5
with Visual Studio 2026
to create a Visual Studio 2022 project.
Why am I doing this?
At work we use cmake 3.23.5 and VS2022.
I want to investigate something at home, but Microsoft no longer provides a VS2022 Community edition, only VS2026.
So this is how I got to my situation.
I am using the command
cmake . -B BUILD -Ax64 -G"Visual Studio 17 2022"
but I get the error
-- Building for: Visual Studio 17 2022
CMake Error at CMakeLists.txt:36 (project):
Generator
Visual Studio 17 2022
could not find any instance of Visual Studio.
-- Configuring incomplete, errors occurred!
See also "C:/Users/John/Desktop/gRPC-Investigation/grpc/cmake/BUILD/CMakeFiles/CMakeOutput.log".
C:\Users\John\Desktop\gRPC-Investigation\grpc\cmake\BUILD>cmake -version
cmake version 3.23.5
CMake suite maintained and supported by Kitware (kitware.com/cmake).
I thought order of installation might make a difference so I’ve done the following.
You cannot generate a solution for a VS version which you don’t have installed, CMake doesn’t support that. Moreso, even if it was somehow possible, it wouldn’t be of much use — if you open an older solution in a newer VS, it will convert it to its latest format.
However, what you can do, is install the appropriate older C++ toolset into your version of VS, and generate a new-version VS solution for use with the old-version toolset (by using CMake’s -T command-line argument or GUI equivalent). The platform toolset for VS 2022 is v143. Google tells me the VS2026 default toolset is v145.
So if you install the Visual Studio 2022 v143 platform toolset into your VS 2026 and pass -T v143 to CMake when generating the solution, you should get a VS 2026 solution using the VS 2022 compiler.
In the office we use VS2017, VS2019 and VS2022. I regularly open a VS2017 or VS2019 solution with VS2022. During the open it asks me if I want to use the old format or convert to VS2022. This implies to me that VS has non-destructive backwards compatibility (/chuckle - words I never thought I would use when describing Microsoft.)
However I think the key point that you and the others are making is:
CMake can only generate solution files for an installed version of VS
VS2026 isn’t supported until CMake 4.2.0
I could install the appropriate C++ toolset, i.e. VS 2022 v143 and it might take care of my problem.