Use shortcut key to generate GUID very quickly in Visual Studio

One of the common tasks involved in the development is GUID’s generation. This is even more frequent when we are working on a SharePoint solutions.  Even during writing unit test we need to imagegenerate  static GUID to validate data’s. Visual Studio comes with a tool called guidgen.exe  ( c:\program files (x86)\microsoft sdks\windows\v7.0a\bin\NETFX 4.0 Tools\guidgen.exe ) which is registered with visual studio as an external tool and invoked from Tools > Create GUID. But whenever you need an unique static GUID you have to navigate to tool and copy the ID evertime. Last few days of my development involved with lots of GUID generation where I found it’s taking time to generate so many guid’s. So, I came up with an small approach  where we can generate a GUID by  just pressing some shortcut key. Behind the seen I wrote a macro for the same and  that is being triggered with the key press.

Here I am not giving any details about macro creation, cutomozation etc .  If you want to know more about the Macro Creation, Configuration, Keyword assignment Please read one of my previous article for step by step guide.

Add document header for files automatically in Visual Studio.

Below is the sample macro code block for macro

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module CreateGUID
    Sub GenerateGUID()
        Dim NewGUID As String = String.Format("{0}", (System.Guid.NewGuid().ToString().ToUpper()))
        DTE.ActiveDocument.Selection.Insert(NewGUID, vsInsertFlags.vsInsertFlagsContainNewText)
    End Sub
End Module

 

Now, when ever you want a GUID,  just use shortcut key for that macro.  🙂

image

Once you are done with basic things working, you can configure the Context Menu and Shortcut key for the same. ( Tools > Customize )

image

Now, you can generate a GUID by pressing  “Alt + G” or Context Menu > Create GUID

image

Sometime you may required GUID in different format, so for that you can create a different macro, and configure as I said the things that you need to take care is string format only..

I hope this will help you !

Thanks !

AJ

Tips and Tricks, Visual Studio , , ,

6 comments

  1. Hi,

    I saved this macro. But it only works when I run in debug from macro ide. When running from macro explorer nothing happens

    Like

Leave a comment