Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
567 views
in Technique[技术] by (71.8m points)

visual studio 2010 - How to run a .bat from inside the IDE

What I want to do is very simple, yet can't find the way to do it.
In my projects I have several .bat files (I know, I'm old) the perform some tasks like running SqlMetal, etc.

I just want to right-click the file and select "run" or something so the bat is executed. How do I do it?

Note: I know I can use Tools -> External Tools, but it's not what I'm looking for

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If each project has a few batch files associated with it then why not include them in the project and add a new external tool and link it with a custom menu item to run the tool? This will give you a list of batch files in each project and a context menu command to run them. The only downside is that it isn't file type specific (it will let you run any file as a batch file).

Here's how to do it...

Create an external tool called "Run batch file"

  1. Set the Command to: CMD.EXE
  2. Set the Arguments to: /c "$(ItemPath)"
  3. Set the Initial directory to: $(ItemDir)
  4. Check the "use output window" checkbox and then Apply to create the command
  5. 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"

Now go to Tools -> Customize and select the commands tab.

  1. Select the Context menu radio button and select "Project and Solution Context menus | Item" from the dropdown.
  2. Now use "Add Command..." to add a new command
  3. In the Categories list select "Tools"
  4. 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.
  5. Move it to the correct position in the list add keyboard shortcuts etc.
  6. Close the dialog.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...