I am unable to use the cl
command in PowerShell.
I tried to add the following command to my PowerShell profile to exec vcbuildtools.bat
, but PowerShell does not recognize cl
command on PowerShell?
&"C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
OS: Windows 10
CL:A can be used as a building, a house, a trophy, a statue, and similar concepts. Just like an English pronoun, you must first identify what you are talking about (a house for example). Then you can use the classifier to show where it is located, or what is near it.
Description. The Clear-Host function removes all text from the current display, including commands and output that might have accumulated. When complete, it displays the command prompt. You can use the function name or its alias, cls .
Using PowerShell.exe Otherwise, the session is the same as any session that is started in the Windows PowerShell console. To start a Windows PowerShell session in a Command Prompt window, type PowerShell . A PS prefix is added to the command prompt to indicate that you are in a Windows PowerShell session.
Just to be clear I'm addressing the asker's issue that cl
is not in the PATH even after running this in PowerShell
&"C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
I think this boils down to the issue that batch file can't export variables to PowerShell (also related: this question), as you've found out with vcbuildtools.bat
. I think it's because PowerShell invokes a cmd.exe subshell to execute the batch file which changes the environment in the subshell but the changes don't propagate to the parent shell i.e. PowerShell.
One way is to use the fact that subshell inherits the environment from the parent shell. So if you run this in PowerShell, the environment set by the batch file is preserved
cmd.exe /k "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat" `& powershell
Take note of `&
. The character has to be escaped because it has a special meaning in PowerShell.
The Pscx module has an Import-VisualStudioVars
function which imports environment variables for Visual Studio. An example usage is
Import-VisualStudioVars 2015 amd64
if you're using VS/BuildTools 2015 and compiling 64-bit programs. You can use Pop-EnvironmentBlock
to revert the changes. See man Import-VisualStudioVars -full
for more information.
Alternatively, Pscx also has an Invoke-BatchFile
function that retains environment changes by a batch file. An example usage
Invoke-BatchFile "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
See man Invoke-Batchfile -full
for more information.
Notes
PowerShellGet
which is shipped with PowerShell 5 and is available as a downloadable installer for PowerShell 3 and 4.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With