Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio - Run Batch File

What I would like

I would like to easily run a batch file without leaving Visual Studio. The batch files are not always the same, they change depending on the solution I'm working with.

What I know so far

I know you can create custom shortcuts in the Tools section of Visual Studio (Under External Tools).

My solutions have various scripts/batch files and I wish there was a way to create shortcuts under a solution folder or some other place that is solution specific.

I can create the scripts but there doesn't seem to be a way to run the script. I don't like having to open Windows Explorer each time I want to run a script.

Perhaps an add-in that would start a process with the selected file in the solution explorer? Or something similar?

like image 781
quip Avatar asked Jul 01 '10 17:07

quip


2 Answers

Here is a full steps on how to add the external tool to run the batch files by right click on the file and select "Run the batch file", also whenever you need to edit the file, just open and edit it.

Here's how to do it...

Create an external tool called "Run batch file"

    1) From Tools-> External Tools, create a new and put the below parameters:
    2) Set the Command to: CMD.EXE
    3) Set the Arguments to: /c "$(ItemPath)"
    4) Set the Initial directory to: $(ItemDir)
    5) ![DO NOT Check the "use output window" check box and then Apply to create the command
    Note where the new command appeared in the list of commands. 
        The external commands are numbered from 1 starting below the divider bar. 
#1 is usually "Create GUID"
To make it easy to remember you can move the new  command to the top, to be the number one command in the list.][1]

    6) Now go to Tools -> Customize and select the commands tab.
    7) Select the Context menu radio button and select "Project and Solution Context menus | Item" from the drop down.
    8) Now use "Add Command..." to add a new command
    9) In the Categories list select "Tools"
    10) From the commands select the "External Command #" that corresponds to the position of the "Run Batch file" custom command you noted the number of in step 5 above.
    11) Move it to the right position in the list add keyboard short cuts etc.
    12) Close the dialogue.

Now right click on the batch file and you should see a "Run batch file" menu item. This will execute th batch file and show it's output in the VS Output window.

Hope it helps.

enter image description here

enter image description here

like image 105
InkHeart Avatar answered Sep 19 '22 06:09

InkHeart


I did this by right clicking the batch file and choosing "Open With", then I added a new editor and used explorer.exe (and then set that to be the default editor).

Add program dialog

like image 24
Shaun Rowan Avatar answered Sep 19 '22 06:09

Shaun Rowan