How to open Developer Command Prompt for vs2015? - visual-studio

I want to create a .bat file that will open Developer command prompt and there i need to change directory "cd .. " path " " and execute few commands there.

The Developer Command Prompt for Visual Studio is nothing more as the normal cmd with a bat script run at the start.
You can run this script by yourself.
call "%programfiles(x86)%\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"

Working on this now.
my current .txt file has a hanged extension of (.bat) Which is batch.
Copy & Paste this within your batch file.
echo off
title My Test Batch File
:: See the title at the top.
echo Test file executed.
echo I am too lazy to write commands again and again.
C:\Program Files (x86)\Microsoft Visual Studio 14.0>
pause

Right Click on your project name under solution explorer, then locate open command line, select developer command Prompt or use shortcut: shift + Alt + ,

Related

Running visual studio code in the current folder with batch file

I can follow below sequence of actions to run the Visual Studio Code in the current folder.
select the location bar in the current folder and run
(ALT + D):
cmd /k code .
I've tried to wrap the code . in the batch file (and place it in a folder where is declared in the PATH variable to run it as its own), it launches "Visual Studio Code" but doesn't close the command window until i close the visual studio code.
i know "start" command need to be there with exit command in the end but so far the combinations i've tried didn't really let me achieve that.
cmd.exe /k code .
exit
Any ideas?
this works for me,
Do not omit the first empty quote
Start "" "C:\Program Files (x86)\Microsoft VS Code\code.exe" <path_to_dir>\.
This works for me (be sure to start code and exit at the bottom of the batch file):
start "" code
exit
If you just want to start vscode from current folder from command line
type
code %cd%
Starts Visual Studio Code in current folder
#start code .
Starts Visual Studio Code in specific folder
#start code "<Specific Folder>"
Starts Visual Studio Code with a specific file
#start code "<Specific File>"
Save file as .bat
It works fine when I create cmd file with that script on the Windows 10 OS:
code c:\\path\\to\\Project | exit
[Run as] VS code extention for "Right click a file to run as the parameter of command in terminal."
https://marketplace.visualstudio.com/items?itemName=plylrnsdy.run-as
I tried this in command prompt and powershell:
call code
It works for me.

How to open Visual Studio Code from the command line on OSX?

The docs mention an executable called code, but I'm not sure where I can find that so I can put it on my path. The zip I downloaded from the VSCode site did not include any such executable. (I am able to run the .app just fine.)
Is this a Windows-only thing?
From the Visual Studio Code Setup page:
Tip: If you want to run VS Code from the terminal by simply typing 'code', VS Code has a command, Shell Command: Install 'code' command in PATH, to add 'code' to your $PATH variable list.
After installation, launch VS Code. Now open the Command Palette (F1 or ⇧+⌘+P on Mac) and type shell command to find the Shell Command: Install 'code' command in PATH command.
After executing the command, restart the terminal for the new $PATH value to take effect. You'll be able to simply type 'code .' in any folder to start editing files in that folder.
⚡️ The Easy Solution.
Download, install and open Visual Studio Code.
Open the Command Palette (⌘ + ⇧ + P on Mac) OR View ❯ Command Palette
🌟 3. Type shell command to find
Shell Command: Install 'code' command in PATH command
Install it and you're done
📟 Here's a complimentary GIF.
After that, you can use code or code . in the terminal.
code
Peace! ✌️
If you'd like to go a little bit further and learn a couple of great tips/tricks for using the VSCode CLI, I made a YouTube video on my workflows.
If you want to open a file or folder on Visual Studio Code from your terminal, iTerm, etc below are the commands which come as default when you install Visual Studio Code
To open Visual Studio Code from command line
code --
To open the entire folder/directory
code .
To open a specific file
code file_name
eg:- code index.html
We since updated the script to the following syntax to support multiple files and folders as arguments and to fix an issue with not detecting the current working directory properly:
code () {
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
}
Update for our VS Code 1.0 release:
Please use the command Install 'Code' command in path or Install 'code-insiders' command in path from the command palette (View | Command Palette) to make Code available to the command line.
For me on Macbook Book Pro 2019 MacOS version 10.15.6, shortcut to open command palette in VSCode was Shift + Command + P.
On opening it one has to just write install code and press enter.
After that just open the terminal and type code your vscode will start opening.
This was the tutorial I was looking for in this thread. It shows the way to open files in Visual Studio Code by writing code .
1.- Open the file
Bash
open ~/.bash_profile
Terminal OS
open ~/.zshrc
2.- Add in your file the :
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
3.- Reinicialize terminal and try in the folder you want to open
code .
4.- Then you can use it as shown in this comment: https://stackoverflow.com/a/41821250/10033560
I have a ~/bin/code shell script that matches the command #BengaminPasero wrote.
#!/bin/bash
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
I prefix ~/bin: to my $PATH which allows me to add a bunch of one off scripts without polluting my ~/.bash_profile script.
Note: Only for Windows Users.
As many folks already suggested ways to open code from command prompt using code . command. This will only open Visual Studio Code Stable build. But If you have downloaded Visual Studio Code Insider build/version (Which has all latest build/features but unstable version) then you need to follow below instructions in windows :
Go to Control Panel\System and Security\System. Click on Advanced System Settings
Click on Environment Variables
Under System Variables tab, Click on Edit for Path Variable
Add a new path C:\Users\tsabu\AppData\Local\Programs\Microsoft VS Code Insiders\bin
(or)
C:\Program Files\Microsoft VS Code Insiders\bin based on location at which you have installed vscode insider in your machine.
Open a new command prompt and type code-insiders . to open vscode-insider
build/version
After opening VSC and pressing (Command + Up + P) I tried typing in "shell command" and nothing came up. In order to get "Shell Command: Install 'code' command in PATH command" to come up, you must do the following:
Press (Command, Up, P)
Type > (this will show and run commands)
Then type Shell Command: Install 'code' command in PATH command. It should then come up.
Once you click it, it will update and you should be good to go!
MacOS X Launch from Command Line docs
On OSX Mavericks I created a bash script named vscode (adapted from the .bashrc in VSCode Setup) in ~/bin:
#!/bin/bash
if [[ $# = 0 ]]
then
open -a "Visual Studio Code"
else
[[ $1 = /* ]] && F="$1" || F="$PWD/${1#./}"
open -a "Visual Studio Code" --args "$F"
fi
vscode <file or directory> now works as expected.
If you are using VS Code Insiders:
code-insiders .
If you are using VS Code:
code .
If you install Your vs code in Download folder you need to move the VS code to Application folder then open the vs code ,then press shift + command + p after you will see the below image. Then you need to type code . Now you are good to go.
Try this one
Open Visual Studio Code and press Command + Shift + P then type Shell in command palette now you are able to find this option like Shell Command : Install code in PATH from suggested list in command palette. Select that options.
Open VSCode via Terminal/Command Prompt
That's it.
Now open your terminal type.
$ code .
Steps to run code . command in mac to start the VSCode app -
Open VSCode
Open command pallet(Cmd+Shift+P)
Enter Shell Command: Install 'code' command in PATH and select
You will get the notification saying Shell command 'code' successfully installed in PATH.
Restart the terminal and enter code .
This will open VSCode from the current folder files in it.
You can use the vscode: protocol that Visual Studio Code defines:
open vscode://file/full/path/to/project/or/file
You can also use
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code
if you do not fancy modifying your path
I discovered a neat workaround for mingw32 (i.e. for those of you using the version of bash which is installed by git-scm.com on windows):
code () { VSCODE_CWD="$PWD" cmd //c code $* ;}
its very simple:
Launching from the Command Line
You can also run VS Code from the terminal by typing 'code' after adding it to the path:
Launch VS Code.
Open the Command Palette (⇧⌘P) and type 'shell command' to find the Shell Command: Install 'code' command in PATH command.
source
https://code.visualstudio.com/docs/setup/mac
I ran: open -a "Visual Studio Code" [folder-name] to open a folder with my Visual Studio Code application. Folder name is optional if you just want to open the application. Not sure if this is exactly your use-case, but hope this helps!
This is what worked for me on Mac OS Catalina -- found here (thanks, Josiah!)
If you're on Mac OS Catalina, you need to edit your .zprofile instead of .bash_profile.
Edit your ~/.zprofile file: vim ~/.zprofile
Add the following code in it, on it's own line: code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
Save the file: :wq
Re-run the updated file: source ~/.zprofile.
Test that running code . opens your current folder in VS Code!
In my case I had to use an alias:
alias code="/<PATH TO VSCODE>/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code"
You can add this alias in your ~/.bash_profile.
I added this to my ~/.profile
alias vscode='/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron'
then
. ~/.profile
afterwards I can just do
vscode
from the terminal
Added this to /usr/local/bin/code, you might have to modify the path if they are different.
#!/usr/bin/env bash
CONTENTS="/Applications/Visual Studio Code.app/Contents"
ELECTRON="$CONTENTS/MacOS/Electron"
CLI="$CONTENTS/Resources/app/out/cli.js"
ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$#"
exit $?
Make executable afterwards
sudo chmod +x /usr/local/bin/code
I had this issue because of VS Code Insiders.
The path variable was there but I needed to rename the code-insiders.cmd inside to code.cmd .
Maybe this is useful to someone.
For windows Users
just type in
>code .
More commands here
https://code.visualstudio.com/docs/editor/command-line
If you're using visual code insiders and you want to open a file or folder in Visual Studio Code insiders from your terminal or any other command line tool then you can refer to the commands below which come by default inside visual studio code insider.
To open Visual Studio Code from command line
code-insiders --
To open the entire folder/directory
code-insiders .
To open a specific file
code-insiders file_name
eg:- code index.html
VSCode now supports it out of the box with version 1.58. Just type:
$ cd path/to/your/directory
$ code .
The instruction given at VS Code Command Line for launching a path are incorrect; the leading colon shown in the example doesn't work. However, launching with a backslash terminated directory name opens the specified directory as expected.
So, for example,
code C:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src\
opens the Visual Studio Code editor in directory C:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src.
Important: The terminal backslash, though optional, is useful, as it makes clear that the intend is to open a directory, as opposed to a file. Bear in mind that file name extensions are, and always have been, optional.
Beware: The directory that gets appended to the PATH list is the \bin directory, and the shell command code launches a Windows NT Command script.
Hence, when incorporated into another shell script, code must be called or started if you expect the remainder of the script to run. Thankfully, I discovered this before my first test of a new shell script that I am creating to start an Angular 2 project in a local Web server, my default Web browser, and Visual Studio Code, all at once.
Following is my Angular startup script, adapted to eliminate a dependency on one of my system utilities that is published elsewhere, but not strictly required.
#echo off
goto SKIPREM
=========================================================================
Name: StartAngularApp.CMD
Synopsis: Start the Angular 2 application installed in a specified
directory.
Arguments: %1 = OPTIONAL: Name of directory in which to application
is installed
Remarks: If no argument is specified, the application must be in
the current working directory.
This is a completely generalized Windows NT command
script (shell script) that uses the NPM Angular CLI to
load an Angular 2 application into a Node development
Web server, the default Web browser, and the Visual
Studio Code text editor.
Dependencies: Unless otherwise specified in the command line, the
application is created in the current working directory.
All of the following shell scripts and programs must be
installed in a directory that is on the Windows PATH
directory list.
1) ShowTime.CMD
2) WWPause.exe
3) WWSleep.exe
4) npm (the Node Package Manager) and its startup
script, npm.cmd, must be accessible via the Windows
PATH environment string. By default, this goes into
directory C:\Program Files\nodejs.
5) The Angular 2 startup script, ng.cmd, and the Node
Modules library must be installed for global access.
By default, these go into directory %AppData%\npm.
Author: David A. Gray
Created: Monday, 23 April 2017
-----------------------------------------------------------------------
Revision History
-----------------------------------------------------------------------
Date By Synopsis
---------- --- --------------------------------------------------------
2017/04/23 DAG Script created, tested, and deployed.
=======================================================================
:SKIPREM
echo BOJ %~0, version %~t0
echo.
echo -------------------------------------------------------
echo Displaying the current node.js version:
echo -------------------------------------------------------
echo.
node -v
echo.
echo -------------------------------------------------------
echo Displaying the current Node Package Manager version:
echo -------------------------------------------------------
echo.
call npm -v
echo.
echo -------------------------------------------------------
echo Loading Angular starter application %1
echo into a local Web server, the default Web browser, and
echo the Visual Studio Code text editor.
echo -------------------------------------------------------
echo.
if "%1" neq "" (
echo.
echo -------------------------------------------------------
echo Starting the Angular application in directory %1
echo -------------------------------------------------------
echo.
cd "%~1"
call code %1\src\
) else (
echo.
echo -------------------------------------------------------
echo Starting the Angular application in directory %CD%
echo -------------------------------------------------------
echo.
call code %CD%\src\
)
call ng serve --open
echo.
echo -------------------------------------------------------
echo %~nx0 Done!
echo -------------------------------------------------------
echo.
Pause
$> open -a "Visual Studio Code" [file-name]
link your currentily folders to vscode.
Windows Registry Editor Version 5.00
; Directory\Background\shell => on empty space
[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode]
"Icon"="C:\\current-folder-vscode\\Code.exe,0"
#="VsCode"
[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode\command]
#="C:\\current-folder-vscode\\Code.exe ."
; Directory\shell => on a folder
[HKEY_CLASSES_ROOT\Directory\shell\vscode]
#="VsCode"
"Icon"="C:\\current-folder-vscode\\Code.exe,0"
[HKEY_CLASSES_ROOT\Directory\shell\vscode\command]
#="C:\\current-folder-vscode\\Code.exe ."
If you install VS CODE using snap. You will need to add /snap/bin in your PATH environment variable.
so - open your .bashrc or .zshrc
and add /snap/bin in your PATH environment variable
reload terminal,
and than code comand will start it

Run a Command Prompt command from Desktop Shortcut

Is it possible to create a desktop shortcut that, when pressed, will open command prompt and run a pre-defined command?
Create A Shortcut That Opens The Command Prompt & Runs A Command:
Yes! You can create a shortcut to cmd.exe with a command specified after it. Alternatively you could create a batch script, if your goal is just to have a clickable way to run commands.
Steps:
Right click on some empty space in Explorer, and in the context menu go to "New/Shortcut".
When prompted to enter a location put either:
"C:\Windows\System32\cmd.exe /k your-command" This will run the command and keep (/k) the command prompt open after.
or
"C:\Windows\System32\cmd.exe /c your-command" This will run the command and the close (/c) the command prompt.
Notes:
Tested, and working on Windows 8 - Core X86-64 September 12 2014
If you want to have more than one command, place an "&" symbol in between them. For example: "C:\Windows\System32\cmd.exe /k command1 & command2".
Yes, make the shortcut's path
%comspec% /k <command>
where
%comspec% is the environment variable for cmd.exe's full path, equivalent to C:\Windows\System32\cmd.exe on most (if not all) Windows installs
/k keeps the window open after the command has run, this may be replaced with /c if you want the window to close once the command is finished running
<command> is the command you wish to run
The solutions turned out to be very simple.
Open text edit
Write the command, save as .bat.
Double click the file created and the command automatically starts running in command-prompt.
Create new text file on desktop;
Enter desired commands in text file;
Rename extension of text file from ".txt" --> ".bat"
Yes. One option you have is to create a batch file containing the command
cmd -c {your command}
or
cmd -k {your command}
The shortcut will then be to this batch file.
This is an old post but I have issues with coming across posts that have some incorrect information/syntax...
If you wanted to do this with a shorcut icon you could just create a shortcut on your desktop for the cmd.exe application. Then append a /K {your command} to the shorcut path.
So a default shorcut target path may look like "%windir%\system32\cmd.exe", just change it to %windir%\system32\cmd.exe /k {commands}
example: %windir%\system32\cmd.exe /k powercfg -lastwake
In this case i would use /k (keep open) to display results.
Arlen was right about the /k (keep open) and /c (close)
You can open a command prompt and type "cmd /?" to see your options.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true
A batch file is kind of overkill for a single command prompt command...
Hope this helps someone else
I tried this, all it did was open a cmd prompt with "cmd -c (my command)"
and didn't actually run it. see below.
C:\windows\System32>cmd -c (powercfg /lastwake)
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\windows\System32>
***Update
I changed my .bat file to read "cmd /k (powercfg /lastwake)" and it worked.
You can also leave out the () and it works too.
You can also create a shortcut on desktop that can run a specific command or even a batch file by just typing the command in "Type the Location of Item" bar in create shortcut wizard
Right click on Desktop.
Enter the command in "Type the Location of Item" bar.
Double click the shortcut to run the command.
Found detailed Instructions here
Using the Drag and Drop method
From the windows search bar type in cmd to pull up the windows bar operation.
When the command line option is shown, right click it and select Open File Location.
The file explorer opens and the shortcut link is highlighted in the folder. If it is not highlighted, then select it.
Hold down the Control key and using the mouse drag the shortcut to the desktop. If you don't see Copy to Desktop while dragging and before dropping, then push down and hold the Control key until you see the message.
Drop the link on the desktop.
Change properties as needed.

How to execute makecab/f command from notepad?

How can I run a command that is located in a folder using a text file. Here is the command
C:\Program Files\GAPS\XML Forms\CSurvey\temp>makecab/f directories.txt
currently I am able to run upto this path "C:\Program Files\GAPS\XML Forms\CSurvey\temp" using notepad by using the following as a notepad content
cmd /k "cd C:\Program Files\GAPS\XML Forms\CSurvey\temp"
But i'm not able to run the makecab/f directories.txt from notepad. how to modify the notepad content so that the makecab/f directories.txt will execute automatically without manually typing the command in run window?
I assume you want to be able to run the above command using a text file?
That does not make much sense, but maybe due to your English level, I can try to answer your question
Open a new notepad text file.
Type the command you want to run:
C:\Program Files\GAPS\XML Forms\CSurvey\temp>makecab/f "C:\Program Files\GAPS\XML Forms\CSurvey\temp\directories.txt"
Notice that you need to specify full path for directories.txt because since you will run this command from somewhere else, you would need to make sure the path is correct.
Save the file as SomeFileName.bat notice that you must save it with .bat not .txt otherwise, the file will not be executable. Also, make sure Windows is not hiding known extensions to avoid having your file named: YourFileName.bat.txt.
There are two ways of solving your problem.
If you want the command window to remain open after finishing the job, then change this line:
cmd /k "cd C:\Program Files\GAPS\XML Forms\CSurvey\temp"
to this one:
cmd /k "cd C:\Program Files\GAPS\XML Forms\CSurvey\temp & makecab/f directories.txt"
Alternatively, though, you could have the command window close automatically upon completing the batch script. In that case replace your command with these two lines:
cd C:\Program Files\GAPS\XML Forms\CSurvey\temp
makecab/f directories.txt
Note the absence of cmd /k. The command window will automatically open when you start the script and it will stay open while the script is executing.

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):
Select "Tools", "External Tools...".
Click Add
Title: &Cmd
Command: cmd.exe
Arguments: /k "c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
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
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
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.
Copy Windows Command Processor from "C:\Windows\System32\cmd.exe" and paste to "C:\Your\Project\Directory\cmd.exe"
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
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\""

Resources