Running MSVC Command Prompt in Windows Terminal From a Folder
Since I'm stuck on Windows, that also means most of the time I'm using MS Visual Studio 2019 for C/C++ development, or at least the MSVC toolchains that it comes with.
Visual Studio has come a long way in the past few years, and I actually don't mind the community version now, it even works with CMake quite well!
But, there are still times that need or prefer to use the command line, and the environment there hasn't changed in many years. If I open the "x64 Native Tools Command Prompt for VS 2019" shortcut, I'm greeted by this ugly thing:
Windows 10 has had a much better terminal for a while now. I've actually switched from using ConEMU to it, exclusively.
Unfortunately, it's also a Windows 10 app, and not and old school executable, so configuring and running it requires a different approach.
Running the VS tools command prompt within Windows Terminal
First thing first, getting the VS 2019 environment to run within Windows Terminal.
These 'environments' are just batch files that setup the proper paths and environment variables, and this one is no different. I just have to find the batch file that is run...in my case:
D:\Programs\VS 2019\VC\Auxiliary\Build\vcvars64.bat
Telling Windows Terminal to run that is pretty straight forward:
- Start Windows Terminal
- Click the down arrow next to the add button on the top of the screen
- Select Settings
This opens settings.json, which houses the configuration for Windows Terminal. To add the MSVC environment, I just need to add a profile to the 'list' array:
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"profiles":
{
"list": [
{
"name": "MSVC x64 env",
"commandline": "%comspec% /K \"\"D:\\Programs\\VS 2019\\VC\\Auxiliary\\Build\\vcvars64.bat\"\"",
"hidden": false,
"closeOnExit": true
},
...
]
}
}
Now Windows Terminal has a 'MSVC x64 env' option under the new/add menu (+ sign).
Good, but this puts me in C:\Windows\System32 which is never where I want it to be. I want to be able to open this from the context menu in a folder from Windows Explorer instead.