Reputation: 7190
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:
What am I missing?
Upvotes: 3
Views: 2035
Reputation: 17668
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.
Upvotes: 3