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.

image

  • 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.

image

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

image

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

image

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.

image

  • 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].

image

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:

image

Summary

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

Calendar

<<  September 2017  >>
MonTueWedThuFriSatSun
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

View posts in large calendar

Month List