Thursday, January 14, 2010

keyboard short cut to create GUID in visual studio

Here is a blog entry about how to setup keyboard short cut for creating GUID.

From the post, copied for my easy reference:

1.Load Visual Studio 2008 and goto Tools -> Macros -> Macro Explorer (Alt-F8 for short)
2.Right-click on “Macros” then select New Macro Project
3.Name your project (eg. GUIDGenerator) and choose a location to save it (note no space allowed in Project Name).
4.This should give you a new project with a “Module1″ sitting underneath it. Right-click on “Module1″ and select “Rename” to give it a more meaningful name (eg. GUIDGenModule).
5.Double-click on the newly renamed module and you should be shown the Visual Studio Macro IDE.
6.Enter the following code (the “D” in ToString can be customised see Leon’s article):
◦view sourceprint?
1 Sub Create_GUID()

2 DTE.ActiveDocument.Selection.Text = System.Guid.NewGuid().ToString("D").ToUpper()

3 End Sub
7.Save and close the Macro IDE.
8.Back in the main Visual Studio window goto Tools -> Options
9.Goto the “Keyboard” option under the “Environment” tab.
10.In the “Show Commands Containing” text box type in “Create_GUID”
11.Select the Macro sub that you just created from the list (it should be the only one)
12.Click inside the “Press Shortcut Keys” textbox then press your desired keyboard shortcut for inserting a GUID (eg. Alt+G as Leon suggested makes a lot of sense).
13.Ensure the “Use Shortcut in” option is “Global” and click on “Assign”
14.Close the options window and you should be able to start using your keyboard shortcut to quickly insert GUIDs into text!
15.If you have any other Visual Studio windows open at the time you will need to close them and reload for the macro for the macro to be loaded (or you can goto the Macro Explorer window and manually load your Macro project)

No comments:

Post a Comment