Using the Visual Studio Developer Command Prompt from the Windows Terminal
Posted on October 25, 2020 by Paul
In this article, I will show you how to use the Visual Studio command line compiler from the Windows Terminal. I will assume that you’ve already installed Visual Studio 2019 on your machine. In my case, I have installed the Community edition with the Desktop development with C++ workload. By default, the installer will create a few links for using the development tools from the classical Windows Command Prompt and we are going to copy some settings from this to the Windows Terminal. My second assumption is that you’ve also installed the Windows Terminal, if this is not the case just open Microsoft Store, search for Windows Terminal and install it.
If you’ve ever played with Windows Terminal you already know why it is nicer to use than the classical Command Prompt, a few examples: tabs, vertical and horizontal splits, a resizable window, zoom in and out, proper copy paste to and from the Terminal, background colors and a lot of other possible customizations.
From the Windows Start menu, find Visual Studio 2019 → x64 Native Tools Command Prompt for VS 2019 and right click on it, chose More and select Open file location. This will open a folder in Windows Explorer, typically this folder will contain a couple of links to cmd.exe customized for development usage. Find the one named x64 Native Tools Command Prompt for VS 2019, right click on it and select Properties. Select the Shortcut tab, if it is not already selected, and copy the content of Target in a new text file. As an example, this is what mine contains:
We need to do some modifications to the above line in order to be able to use it: remove %compspec%, escape the double quotes and replace each backward slash from the path with two forward slashes. You should end up with something like this (if you have the Professional or Entreprise editions of Visual Studio change the line accordingly):
Next, open the Windows Terminal settings, this is a JSON file that can be customized. You can access the Settings by clicking on the downward arrow from the Windows Terminal menu. The Settings file should contain a few predefined profiles. For our particular case, easiest approach is to duplicate the settings for cmd.exe profile, e.g. in my case:
Duplicate (copy and paste) the equivalent of the above for your case in the settings.json file.
Please note the guid variable, this is a unique identifier for each profile and we need to generate one. From the Windows Start menu open a classical x64 Native Tools Command Prompt for VS 2019 and write:
The above should start an app named Create GUID. Select option 4 Registry Format, press New GUID and than Copy, replace the guid value from the duplicated profile with the value that you just copied (hint you can paste the copied guid).
Optionally, change the name value from the Settings file to something more descriptive e.g.: x64 Native Tools Command Command Prompt for VS 2019
Next, let’s append to the end of the commandline the modified path to vcvars64 from above.
You should end up with something like this:
Optionally, you can start in a particular directory instead of the default one by setting the value of startingDirectory, e.g:
Save the settings.json file and reopen Windows Terminal. If there was any syntax error in settings.json you should see some warning message in the Windows Terminal, otherwise it should start normally.
Let’s try our new profile - from the drop down menu of the Windows Terminal (down arrow) select your new custom entry e.g. x64 Native Tools Command Command Prompt for VS 2019 if you followed this tutorial. As an example, this is what I see on my machine if I open the x64 Native … profile and invoke the cl.exe compiler:
If you prefer PowerShell to the Command Prompt for command line development, the procedure is similar. Duplicate the existing PowerShell profile from the Windows Terminal settings and replace the guid with a new value. Next, replace the value of commandline with:
As an example, this is how it looks on my machine (you may need to adapt it a bit for your particular case):
At this point, you can use the Visual Studio developer tools from Windows Terminal. If you need to learn more about how to configure Windows Terminal check the documentation. For more info about using the command line for development check the Microsoft documentation.