A Visual Studio Macro to insert a new Guid
I've been trying to create some SharePoint Content Types and List Definitions recently, and everyone who done that before knows what you need for that: Guids, and quite a few of them. One for each Field, Feature, Solution... So instead of using GuidGen, I wanted something that inserts a new Guid at the cursor position in the Editor when I press a certain keyboard shortcut.
Luckily, this is rather easy with the Macro Editor. Just create a new Macro/Module and enter this code:
Sub InsertGuid() Dim newId As String = Guid.NewGuid().ToString("B") Dim doc As Document = DTE.ActiveDocument Dim textDoc As TextDocument = CType(doc.Object("TextDocument"), TextDocument) textDoc.StartPoint.CreateEditPoint() textDoc.Selection.Insert(newId) End Sub
You can then go to Tools / Options / Environment / Keyboard and look for the Macro you just created (Macros.MyMacros.SomeModule.InsertGuid) and assign a Keyboard shortcut to it.