1
votes

As titled, using Powershell after executing

PS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build> .\vcvarsall.bat amd64

then programs like cl, nmake or msbuild should be available on the path, but they are not

PS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build> cl cl : The term 'cl' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

  • cl
  • ~~
    • CategoryInfo : ObjectNotFound: (cl:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

Specs:

  • VS 2019 Community Edition with the "Desktop development with C++" workload:
    • MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.28)
    • Windows 10 SDK (10.0.18362.0)
    • Just-In-Time debugger
    • C++ profiling tools
    • C++ CMake tools for Windows
    • C++ ATL for latest v142 build tools (x86 & x64)
    • Test Adapter for Boost.Test
    • Test Adapter for Google Test
    • Live Share
    • C++ AddressSanitizer (Experimental)
  • Win10 Pro N x64, 20H2, 19042.746

What am I missing?

1

1 Answers

2
votes

Powershell executes the batch file in a child cmd process. The VS environment is set in that cmd process, then gets discarded when the process ends and control returns to Powershell.

The straightforward solution is to reverse the sequence, and set the VS environment before starting the Powershell session so that PS inherits it. Assuming a usual VS installation with the correct VS160COMNTOOLS environment variable set, this can be done by running the following at either a command prompt, via Start / Run, or from PS itself.

cmd /c ""%VS160COMNTOOLS%\..\..\VC\Auxiliary\Build\vcVarsAll.bat" amd64 && start powershell"

See also In a CMD batch file, can I determine if it was run from powershell? and How can I use PowerShell with the Visual Studio Command Prompt? for more discussion and possible alternatives - both for returning environment variables from batch files to PS in general, and for the VS environment in particular.