Welcome to MSDN Blogs Sign in | Join | Help

Sara Ford's Weblog

My adventures embracing open source on CodePlex and at Microsoft

News

    • Did you know... All author proceeds go directly to sending Hurricane Katrina survivors to college.

      Microsoft Visual Studio Tips book

      Recent Entries

Did you know… You can run external tools within Visual Studio? - #201

It’s the External Tools Tip of the Day series!!

Okay I have to admit, I’m not the local expert in External Tools, so I could really use help with examples.  I can talk about the functionality all day long, but nothing is better than real world examples.

Let’s start with the basics.  Go to Tools – External Tools to bring up the External Tools dialog.  You’ll notice a set of built-in tools ready to go for you.

Tools - External Tools

Note that I circled the list of external tools.  This list maps directly to the list presented in the Tools menu, as shown below.

External tools listed on Tools menu

The first time I made this connection I was taken aback.  I probably saw this list of tools for years, but never knew it came directly from the External Tools dialog.

Technorati Tags: ,
Posted: Thursday, April 24, 2008 3:00 AM by saraford

Comments

Steve Andrews said:

I have a bunch of External Tools set up.  Some examples are invoking MSBuild for a custom build file and getting the strong-name signature for a signed (and compiled) project.

# April 24, 2008 9:25 AM

Serge Wautier said:

> but never knew it came directly from the External Tools dialog

You mean there's a human being behind this blog? :-)

# April 24, 2008 9:45 AM

MarcT said:

I have several of the TF Power Tools linked there, such as Branch History and Blame/Annotate. It's easy to set the arguments to the currently active file, so it's almost like they're built in.

The other tip is to assign them keyboard shortcuts, which is a pain because they show up there as "External Tool 1", and I've got do figure out which tool that means.

# April 24, 2008 12:31 PM

Chris Martinez said:

One of my personal favorite uses of "External Tools" is setting up the CScript debugger to automatically start debugging scripts directly from Visual Studio .NET.

Admittedly, I've shifted most of my scripting to PowerShell these days, but there is still the occasional need for JScript and/or VB Script.  Debugging standalone scripts is usually a pain.  Using the "External Tools" dialog you can make it a snap!

Steps to setup the CScript debugger to launch and debug your script directly from Visual Studio:

1) In Visual Studio, Tools -> External Tools

2) Click "Add"

3) Title = CScript Debugger

4) Command = C:\Windows\System32\cscript.exe

5) Arguments = //NOLOGO //X "$(ItemPath)"

  NOTE: The $(ItemPath) VS Marco maps the path to

  the script you currently have open

6) Initial Directory = "$(ItemDir)"

  NOTE: The $(ItemDir) VS Marco maps the directory

  to the script you currently have open.  This

  addresses path resolution if your script relies

  on external files located in the same relative

  directory.

7) Check "Use Output Window"

8) Click OK

If you want to get even fancier, you can add a custom toolbar button (and/or toolbar) and attach the external command to it.  Essentially, you can make a "Run" button just like you have for other .NET code.

To debug a script, open any compatible script in Visual Studio.  For example (HelloWorld.js):

function main()

{

   WScript.StdOut.WriteLine( "Hello world!" );

}

main();

Now either click Tools -> CScript Debugger or your fancy toolbar button.  The Visual Studio "Just-In-Time Debugger" dialog will pop up.  Select the current instance you are using.  (I've never figured out how to automatically select the current running instance of VS.NET as the debugger, but that would be a nifty addition).  The debugger will break on the first executable line of code in the script.  Debugging can resume using all of the typical Visual Studio .NET debugging features.

You'll also notice that since the "Use Output Window" is checked, the standard output is directed to Visual Studio.  If you open the Output Window (View -> Output) and change the option in "Show output from" to "CScript Debugger", you will see all of the redirected output.  In this case - "Hellow world!".

Happy scripting and debugging!

# April 24, 2008 2:30 PM

Gregor Suttie said:

Ben's blog shows you an example such as you mentioned - in this case how to run subsonic from the VS IDE

http://blog.benhall.me.uk/2007/10/setting-up-subsonic.html

Cheers

Gregor

# April 25, 2008 5:32 AM

Ben Hall said:

Thanks for point that out Gregor.

Readers might also be interested in this post about executing unit testing frameworks

http://blog.benhall.me.uk/2008/01/executing-mbunit-gui-and-console-from.html

# April 25, 2008 7:02 PM

Mike Adams said:

This is my favorite external tool: Windows Explorer

http://dotnettipoftheday.org/tips/explorer-in-tools-menu.aspx

I also set a keybinding, so I can select the file from the solution explorer, press CTRL + M, CTRL + E and see the file in Explorer. This is extremely handy for batch files in the solution and editing the Web.config outside of source control.

# April 28, 2008 12:13 PM

xjb said:

# January 4, 2009 7:55 PM
New Comments to this post are disabled
Page view tracker