简体   繁体   中英

Change Default Visual Studio Command Prompt Location

How to set the default visual studio command prompt location so that I can go straight to my project's directory instead of using the usual navigation.

For Visual Studio 2017 Command Prompt, you need to set environment variable VSCMD_START_DIR to the directory where you want to end up after the command prompt initializes.

I use this script:

set VSCMD_START_DIR=%1 "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat"

It accepts the directory as the first (and only) argument.

Add it as an external tool to Visual Studio (2008 shown here, should be similar in other versions):

  1. Select "Tools", "External Tools...".
  2. Click Add
  3. Title: &Cmd
  4. Command: cmd.exe
  5. Arguments: /k "c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
  6. Initial Directory: $(SolutionDir)

在此处输入图像描述

Note the arguments come from the "Visual Studio 2008 Command Prompt" shortcut. Yours may vary.

You can can customize the toolbar and add a button for this command as well using "Tools", "Customize...". Open the Tools menu and locate the last External Tool you created and drag it onto the toolbar.

When you click the button, it will open a command prompt in the current solution's root directory.

In Visual Studio 2013 ,

Right click on " Developer Command Prompt for VS2013 " shortcut (which you can find in the "Common7\Tools\Shortcuts" folder from where you installed your VS2013) and choose " Properties ",

Change the: " Start in: " directory to your desired location.

Navigate to the "vcvarsall.bat" file. For me the path is:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat

Add this line to the bottom of the script:

cd /d "D:\WhereverYouWant"

skol

You can put these lines in a batch script (vcvar.bat) located in the directory you want to start with:

@echo off

set VCDIR=%ProgramFiles%\Microsoft Visual Studio 10.0\VC
if not exist "%VCDIR%" set VCDIR=%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC
call "%VCDIR%\bin\vcvars32.bat"

Fire a command prompt in this directory, and call vcvar.bat . You now have the VS environment in the command prompt.

this will add a menu entry "my compiler " to each directory giving you access to the command prompt in the directory. save it as something.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\My Compiler]

[HKEY_CLASSES_ROOT\Directory\shell\My Compiler\command]
@="cmd.exe /k   \"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\vcvarsall.bat\""

For Developer Command Prompt for VS 2019 you can set VSCMD_START_DIR environment variable with the following command:

setx VSCMD_START_DIR C:\your-folder
  1. Copy Windows Command Processor from "C:\Windows\System32\cmd.exe" and paste to "C:\Your\Project\Directory\cmd.exe"
  2. Edit Visual Studio Command Prompt shortcut by replacing %comspec% with "C:\Your\Project\Directory\cmd.exe" in the Target field.

So the shortcut's Target should look something like: "C:\Your\Project\Directory\cmd.exe" /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" amd64

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM