Wednesday, October 28, 2009

Hack 77. Master the Visual Studio Command Prompt











 < Day Day Up > 





Hack 77. Master the Visual Studio Command Prompt





The Visual Studio

command prompt

(VSCP) is a command prompt that loads

environmental settings for Visual Studio and the .NET Framework. What

this means is that you can open the command prompt and type in the command

for a Visual Studio or framework tool, and it will work without you

having to type the full path or navigate to where that tool is

located. (VSCP also sets certain environment

variables, without which many of these tools would not function

correctly.)





To use the VSCP, you need to navigate to Start Program

Files Microsoft Visual Studio .NET 2003 Visual

Studio .NET Tools Visual Studio .NET 2003 Command Prompt.

(If you are using a different version of Visual Studio, this menu

path will be slightly different.)





Figure 10-1 shows an example of the Visual Studio

.NET 2003 Command Prompt.







Figure 10-1. Visual Studio .NET 2003 Command Prompt







From the command prompt, you can access any of the

various tools you commonly need to use from the command prompt. Some

of the more common utilities that you will use while developing

applications are:






sn.exe





Used to strongly sign assemblies [Hack #54]






gacutil.exe





Used to add assemblies to the global assembly cache






xsd.exe





Used to generate strongly typed DataSets from XML schemas [Hack #49]






ildasm.exe





Used to view the Intermediate Language code generated by your code

[Hack #63]






wsdl.exe





Used to generate web services code based on

Web Service Description

Language (WSDL) files









As you can see, a number of useful tools can be quickly accessed

through the Visual Studio command prompt.







10.2.1. Add the Visual Studio Command Prompt as an External Tool





Because of all the helpful utilities available

through the VSCP, you might frequently find yourself opening the

command prompt and then navigating your way to your project or

solution directory. There is a better way. You can add the VSCP to

Visual Studio's Tools menu and have it automatically

open to your project or solution directory:





  1. Open the External Tools configuration window through Tools

    External Tools.

  2. Click the Add button.

  3. Set the name to something like:

    Visual Studio Command Prompt



  4. Set the command to:

    C:\WINDOWS\system32\cmd.exe



  5. Set the arguments to:

    \k c:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\

    vsvars32.bat



  6. Set the initial directory to any of the available options. (These

    include $(SolutionDir) and

    $(ProjectDir), which would place you in the

    solution directory or project directory, respectively.)

  7. Click OK.



Figure 10-2 shows an example of the External Tools

[Hack #33] dialog with

these settings entered.







Figure 10-2. External Tools dialog







The VSCP will now be added as a tool on the Tools menu. You will be

able to quickly get to the tool and even have it open in the

directory of your choice.









10.2.2. Add the Visual Studio Command Prompt to the Explorer





Another way to get the VSCP at your

fingertips is through a little registry hack that will add an

"Open VS command prompt here"

option in the Windows Explorer. The easiest way to add these registry

settings is to create a .reg in your favorite

text editor with the following code:





Windows Registry Editor Version 5.00



[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\VSCP]

@="Open VS Command Prompt Here"



[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\VSCP\command]

@="cmd.exe /k \"C:\\Program Files\\Microsoft Visual Studio .NET

2003\\Common7\\Tools\\vsvars32.bat\""



[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Drive\shell\VSCP]

@="Open VS Command Prompt Here"



[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Drive\shell\VSCP\command]

@="cmd.exe /k \"C:\\Program Files\\Microsoft Visual Studio .NET

2003\\Common7\\Tools\\vsvars32.bat\""







You will, of course, need to modify the path to reflect the version

of Visual Studio that you are using and where you have it installed.

Then save the file with a .reg extension. When

you double-click on the .reg file, you will be

asked if you want to add this information to your registry. After

adding this information to your registry, you will then see an option

in Explorer like the one shown in Figure 10-3.







Figure 10-3. Choosing Open VS Command Prompt Here







You will now be able to right-click on a folder in the tree view of

Explorer and then choose "Open VS command prompt

here" and VSCP will be opened in that directory.





The Visual Studio command prompt is a valuable tool, and having it at

your fingertips no matter where you are is very handy.









10.2.3. See Also





  • Section 13.8Combine

    the Visual Studio Command Prompt and the Command

    Window" [Hack

    #98]

















     < Day Day Up > 



    No comments: