24 June 2009

Bye Bye GuidGen.exe!

While developing in Visual Studio and I needed to create a new guid, I always used the “Create GUID” under the Tools dropdown menu. This menuitem started the “guidgen.exe” application and using this was a fine method, until I attended the last DevDays 2009 (The Hague, Netherlands). There I saw a demonstration of a much easier way to create a new guid in Visual Studio by making use of a simple macro. (Thanks Wouter)

Below is the explanation on how to implement this macro.
1. Open the Macro Explorer and Load or Create a Macro Project.

NewMacroProject

2. Inside the macro IDE, create a method to generate a new guid.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module Module1
    Sub GenerateGuid()
        If (DTE.ActiveDocument IsNot Nothing) Then
            DTE.ActiveDocument.Selection.Text = Guid.NewGuid().ToString("B")
        End If
    End Sub
End Module
3. Save and close the macro IDE.
4. For the finishing though, create a keyboard shortcut to activate the GeneratGuid macro. I like to use the combination CTRL+K, CTRL+G

ShortcutGenerateGuid

5. Now it is so easy to create a new guid…..just by pressing your favourite keyboard shortcut.

CreateGuid

CreateGuid2

Bye Bye GuidGen!