Friday, December 3, 2010

Quick Tip: Right-click VS 2010 Command and Admin Command Prompt

It seems that I've become very familiar with this command:

xsd /c /l:cs schema.xml

If you're not familiar with it, this allows you to parse a schema into a strongly typed class, which then allows you to deserialize an XML document to that type. Pretty nifty, but it requires being in a "Visual Studio 2010 Tools" command line prompt. This is a special option in the VS menu that sets up some environment path variables to make it easy to access the various command line tools that are available.

If you've been doing it the slow way (like me) you'll appreciate this tip. I can't tell you how many times I've navigated to a target folder, then copied the path. Next, I'll open my start window, navigate to the Visual Studio 2010 section and then expand the tools to ultimately open the command prompt. For certain tasks that require elevated permission, I then have to remember to right-click and choose "run as..." so I can execute the prompt as an administrator. Finally, I type "cd" then right-click to paste the folder path and change to the target directory, and I'm ready to roll.

I want to thank Jay Frysinger for sharing with me a registry script that makes it all go away. Now, I simply navigate to the folder I want, right click it, and choose "VS 2010 Prompt" or "VS 2010 Admin Prompt" and I'm there! I don't know the original source of the script (may have been his) but it is very useful.

To use it, first back up your registry (right, isn't that what "they" say to do every time?) and then paste the following into NotePad or your text editor of choice (notice I did not say "Integrated Development Environment" even though I know that's what NotePad still is for some of you). Save it as VS2010Script.reg. Once saved, you can double-click on the file and it should merge the changes directly into your registry to provide the new right-click options.

If you are on a 32-bit system (they still have these, right?) then be sure to edit the script to remove the extra (x86) in the program files path before saving.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\cmd]
@="VS 2010 Prompt"
"NoWorkingDirectory"=""
"Extended"=-

[HKEY_CLASSES_ROOT\Directory\shell\cmd\command]
@="cmd.exe /k \"pushd %L && \"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\vcvarsall.bat\" x86\""

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="VS 2010 Admin Prompt"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /k \"pushd %L && \"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\vcvarsall.bat\" x86\""

[HKEY_CLASSES_ROOT\Drive\shell\cmd]
@="VS 2010 Prompt"
"NoWorkingDirectory"=""
"Extended"=-

[HKEY_CLASSES_ROOT\Drive\shell\cmd\command]
@="cmd.exe /k \"pushd %L && \"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\vcvarsall.bat\" x86\""

[HKEY_CLASSES_ROOT\Drive\shell\runas]
@="VS 2010 Admin Prompt"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Drive\shell\runas\command]
@="cmd.exe /k \"pushd %L && \"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\vcvarsall.bat\" x86\""

Jeremy Likness

No comments:

Post a Comment