Generating Visual Studio Projects for previous VS versions

Is it possible to generate a msvc 16 or 15 project with only msvc 17 installed?

So, when I installed 2022 I decided to remove my old IDE installs and just install the the compilers as packages to 2022 instead of having three copies of the full IDE. I can easily enough open my old solutions and build with them, but I noticed CMake wouldn’t generate new projects as of 3.22 it complains it can’t find Visual Studio when I ask it to generate projects for 2019 or 2017. Curious if there is away around this or if I just need to keep a light way installation of all three.

You need to use the -T argument to select the older toolchain with newer VS installs. Requesting VS 2017 or VS 2019 requires that version of VS to be installed.

Something like cmake -G "Visual Studio 17 2022" -T "v142" should suffice to get the 2019 toolchain (v141 is the 2017 toolchain).

Perfect answer. I noticed the GUI supports it as well which is good for the rest of my team. I appreciate the help.