Generating GUIDs from Visual Studio 2008
I find I have to generate GUIDs often (mostly due to using WiX) and the in-built Tools > Create GUID tool is too cumbersome for this. I found a blog post that has a simple macro you can customize to bind a keyboard shortcut to paste in a new GUID Here are some full instructions, using their simple macro code:
- Tools > Macros > Macro Explorer (or hit ALT+F8)
- Right click Macros, choose New Macro Project…
- Choose a location for the Macro project and give it a meaningful name then click Add
- Rename Module1 to something more meaningful, then double-click to edit the module
- Insert the code to paste a new GUID into the current cursor position / selection:
Public Sub PasteNewGuid() DTE.ActiveDocument.Selection.Text = “{” & System.Guid.NewGuid().ToString(“D”).ToUpper() & “}” End Sub
- Save the macro project and close the Macro IDE
- In Visual Studio: Tools > Options, select Environment > Keyboard
- Find the macro command you created (you can use the Show commands containing: to search on guid)
- Select the command in the list
- Ensure Use new shortcut in: has Global selected
- Place the cursor in Press shortcut keys: and hit the shortcut (ALT+G for me)
- Hit OK
- Test it out