Execute Command Files from Visual Studio 2010

On a recent project we used custom Visual Studio build files to build and deploy the code to different environments, i.e. Test and Production.  We created command files to pass the correct arguments to the build so it would be easier to run.  We never liked the fact that we need to open a command window and navigate to our solution folder to run the builds.  We thought, “There has got to be a way to do that from with in visual studio”, and we were right.  Devlin Liles details the steps we used to set that up in Visual Studio 2008 in his blog post titled Batch File and Command File running In Visual Studio.

I wanted to set that up in Visual Studio 2010 today and found the steps a little different so wanted to share how to set it up in Visual Studio 2010.

To realize the ability to execute command or batch files from within Visual Studio 2010 we need to perform the following steps:

  1. Create the External Command
  2. Adding the Command to the Context Menu

Setting up the External Command

  • Open the External Tools dialog by opening the Tools->External Tools menu.


  • Click the add [Add]  button to create a new External Tool and enter the following information:
Title E&excute Command…
Command C:\WINDOWS\System32\cmd.exe
Arguments /K $(ItemPath)
Initial directory $(ItemDir)
Use Output Window Checked
Prompt for arguments Not Checked
Treat output as Unicode Not Checked
  • Click the [Apply] button to save these changes, but before you click [OK] take now of a how many External Tools are listed here.  In my case it was the only external tool that had been defined so it will be assigned to External Tool 1
  • You can click [OK] now to close the External Tools dialog.

Adding the Command to the Context Menu

Now that we have our external command created we need to add it to the context menu for Solution Explorer items.

  • Open the Customize dialog by right clicking somewhere in the toolbar area to bring up the context menu and selecting Customize from the bottom of the menu.


This is where the steps for Visual Studio 2010 are different than Visual Studio 2010.  If you are using Visual Studio 2008 follow the instructions on Devlin Liles blog.

  • Select the [Commands] tab


  • Under Choose a menu or toolbar to rearrange: select Context menu: and in the drop down select Project and Solution Context Menus | Item.


I want my “Execute CMD…” command to be positioned above the “Edit WCF Configuration” items, so select “Edit WCF Configuration” and click the [Add Command…] button.


  • On the Add Command dialog in the Categories list select Tools.  Know in the Commands list scroll down until you see the External Command you are looking for.  Remember ours was External Command 1.  Once you find it select it and click [OK].


Now we see that External Command 1 is shown above the “Edit WCF Configuration” command, right were I wanted it. 

  • Now you can click [Close] button, open a solution and when you open the context menu in Solution Explorer you see the following:



This addition to Visual Studio has come in really handy for running common commands or batch files you might need to automate more mundane task.

blog comments powered by Disqus


<<  January 2022  >>

View posts in large calendar

Month List