windowsvisual-studiovisual-c++visual-studio-2019visual-studio-2017-build-tools

Calling vcvarsall.bat gives "Windows cannot find powershell.exe" on Windows 7 / VS 2019 Build tools


I previously had Visual Studio 2015 (14.0) Build tools installed, and I could build a simple C++ program, without any IDE, with:

call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
cl helloworld1.cpp

Now that I installed Visual Studio 2019 Build Tools, calling vcvarsall.bat gives this message:

Windows cannot find 'powershell.exe'

but after closing the dialog, it still continues (!). But then it fails with:

cl : Command line error D8027 : cannot execute 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.26.28801\bin\HostX64\x64\c1xx.dll'

I don't see why powershell would be mandatory to just set a few environments variables and set up everything to use cl.exe.

Question: what's the proper way to call cl.exe with VS Build Tools 2019?

Shouldn't we call vcvarsall.bat first, like with previous versions?

(important: I'm looking for a 100% terminal mode, no IDE)

enter image description here


Solution

  • The official way would be to to add %SystemRoot%\System32\WindowsPowerShell\v1.0 to your PATH either permanently or just before calling vcvarsall.bat.

    An alternative is to do a set VSCMD_SKIP_SENDTELEMETRY=1 before calling vcvarsall.bat. This works because vcvarsall internally calls vsdevcmd, which in turn uses powershell to configure "send telemetry if user's VS is opted-in". However, the telemetry step is bypassed when VSCMD_SKIP_SENDTELEMETRY is defined (though this appears to be undocumented, and thus subject to change in future versions), then powershell is no longer used or required.