If you work on C++ projects on Windows that need to be built with multiple Visual Studio C++ compiler versions, you need some way to manage the installations of all these build environments. Either you have multiple IDEs installed, or you know about build tools (https://aka.ms/vs/17/release/vs_BuildTools.exe) and maybe keep only the latest full VS IDE plus older Build Tools.
However, it turns out that you can have just the latest IDE but with multiple toolchains installed for older compiler targets. You won't even need the Build Tools.
To use these toolchains you need to install them in your chosen VS installation and then call vcvarsall.bat with an appropriate parameter.
You can even have no IDE installed if you don't need it but only the Build Tools with the required toolchains. That's useful when you use a different IDE like JetBrains Clion or Visual Studio Code. Note, however, that to be license- compliant, you still need a valid Visual Studio subscription.
Installing the toolchain
1. Go to the Visual Studio Installer and click "Modify" on your main VS version (2022 in my case).
2. Go to "Individual components" and search for the appropriate toolchain. For example, to get the latest VS2019 C++ compiler in VS 2022 installer, you need to look at this:
If you do your compilation in Powershell, vcvarsall.bat is not very helpful. It will spawn an underlying cmd.exe, set the necessary env vars inside it, and close it without altering your PowerShell environment.
(You may try to do some hacks of printing the environment in the child cmd.exe and adopting it to your Pwsh shell, but that's a hack).
For setting up a development environment from PowerShell, Microsoft introduced a PowerShell module that does just that.
Unfortunately, Qt Creator doesn't detect the toolchains in a single Visual Studio installation as multiple kits. You have to configure the compiler and the kit yourself:
I am a script, how do I know where Visual Studio is installed?
If you want to query the system for VS installation path programatically (to find either vcvarsall.bat or the DevShell PowerShell module) you can use the vswhere tool (https://github.com/microsoft/vswhere).
It's a small-ish (0.5MB) self-contained .exe so you can just drop it in your repository and don't care if it's in the system. You can also install it with winget:
winget install vswhere
It queries the well-known registry entries and does some other magic to find out what Visual Studio installations your machine has.
By default it looks for the latest version of Visual Studio available and returns easily parseable key:value pairs with various infos about the installation. Most notably, the installation path in installationPath.
It also has various querying capabilities, like showing only the VS installation that have the C++ workload installed.
For example, to get the installation path of the newest Visual Studio with C++ workload, you call:
I haven't found an easy way to query vcvarsall for something along the lines "give me the latest available toolchain in a given VS product line (2019, 2022 etc.)". So if you call an explicit version (like 14.29) and a newer one appears, you will still be looking for the older one. However:
When vcvarsall.bat is called without any toolchain parameter (vcvars_ver), it defaults to itself so you may assume that it's the latest one in this installation folder.
Microsoft seems to stop bumping the relevant part of the version of the Visual Studio C++ compiler once the next version of VS is out. So for example it seems that 14.29 will be a proper target for VS2019 C++ compiler until the end of time.
The KDAB Group is a globally recognized provider for software consulting, development and training, specializing in embedded devices and complex cross-platform desktop applications. In addition to being leading experts in Qt, C++ and 3D technologies for over two decades, KDAB provides deep expertise across the stack, including Linux, Rust and modern UI frameworks. With 100+ employees from 20 countries and offices in Sweden, Germany, USA, France and UK, we serve clients around the world.
Miłosz Kosobucki
Senior Software Engineer
Miłosz Kosobucki is a Senior Software Engineer at KDAB
Our hands-on Modern C++ training courses are designed to quickly familiarize newcomers with the language. They also update professional C++ developers on the latest changes in the language and standard library introduced in recent C++ editions.