Visual Studio has a nice feature that is not so explored by some developers that is the ability to start external tools from inside Visual Studio. So, to demonstrate how to use it, let’s create a quick example. We are going to create a menu item under the Tools menu that will pick the selected text on your code and perform a search on Google.
- Open Visual Studio 2008;
- Click on Tools menu and select External Tools;
- From the External Tools dialog, click Add;
- Type Google Search on the title textbox. That is the name that will be displayed under the Tools menu;
- On the command toolbox, type the full path for the Internet Explorer (or your chosen web browser). In this example I am using IE on the following path: C:\Program Files\Internet Explorer\iexplore.exe;
- The arguments textbox is where you add parameters to be passed to the external tool defined on the command textbox. You may pass a literal text or dynamic information. To check the dynamic items that may be passed to the tool, click on the arrow button beside the arguments textbox. You will see a list of items such as solution and project file names, current text that is the current selected text and so on. For our example is just a matter of concatenate a default Google search address such as http://www.google.com/search?hl=en&q=&btnG=Search and as the query string “q”, let’s add an expression to get the current selected text. If you don’t have the expression on the top of your head, you may click on the item to get the expression first and then edit it to get your final parameter. Our final argument might be http://www.google.com/search?hl=en&q=$(CurText)&btnG=Search;
- The initial directory is optional for this example but sometimes is important to define it if the external tool needs to read data from the current directory for example;
- If you want to be prompted to enter the argument mark the Prompt for arguments option;
- If you are calling a bat file for example, you may mark the Use Output window to display the results on the Output window;
- Click OK;
- Open a code file and select a text;
- Go to Tools menu and click Google Search.
Voilà! The results are displayed.