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.  :)


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


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


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 !