Long story shorts, those “helpers” provided by Visual Studio to setup your development environment are horribly slow, and seems to get slower on every new version. So, if you’re like me and don’t like to wait 2 to 10 seconds every single time you need a working environment in which you can call
cl, then the following might interest you.
Those scripts are “helpers” which will ultimately invoke the one which actually setups the environment so that you can invoke the compiler from the command line, but the thing is they run a lot of other scripts which have nothing to do which this (if you’re curious, see the
vsdevcmd\ext folder’s content, everything in it is executed…)
So to “speed things up” (still slow for something that just sets a few environment variables…) you can directly invoke the extension that only sets the Visual C(++) compiler in that folder (
vcvars.bat) And since it’s a pain in the ass because it’s not meant to be called as a standalone, here is the minimum amount of boilerplate that I had to write to be able to call it:
@echo off :: configure for x64 set VSCMD_ARG_HOST_ARCH=x64 set VSCMD_ARG_TGT_ARCH=x64 set VSCMD_ARG_APP_PLAT=Desktop :: the version of visual studio you're using (needs to be set for vcvars.bat to work, and also, needs to end :: with a \ otherwise vcvars.bat will fail -_-) set VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio\2022\Community\ :: setup the MSVC compiler (and only that, not all the bullshit that the "official" VsDevCmd script does...) call "%VSINSTALLDIR%\Common7\Tools\vsdevcmd\ext\vcvars.bat" call "%VSINSTALLDIR%\Common7\Tools\vsdevcmd\core\winsdk.bat"
On my machine, calling this takes approximately 150ms, while calling the usual
VsDevCmd.bat takes more than 2 seconds…