Generating GUIDs for WiX with a Visual Studio Macro
Lately I’ve been doing some work with WiX (Windows Installer XML) and have needed to generate fresh GUIDs frequently.
For those infrequent uses, the online UUID Generator worked great, but WiX needs a lot of GUIDs and I got tired of copy/pasting them.
Unfortunately there’s no built-in support for this, but it’s fairly straightforward to set up a VB.NET macro for this purpose. I ran across the macro code over here which shows how to bind to a keystroke, but I’ll illustrate how to bind the macro to a toolbar button instead.
- Bring up the Macro IDE (Tools > Macros… > Macros IDE…)
- Add a new module called "GuidModule"
- Copy/paste the following code into the GuidModule:
REM Insert a new GUID at the insertion point
Sub InsertGUID()
Dim ts As TextSelection = ActiveDocument().Selection
Dim guid As System.Guid = System.Guid.NewGuid()
ts.Insert(guid.ToString().ToUpper())
End Sub
Your screen should look like this:
- Hit the close button in the corner to go back to the main Visual Studio window
- Right click on the toolbar window to bring up the list of toolbars, and click Customize… at the bottom
- Click New…
- Give the toolbar a name (e.g. "Guid") and click OK
- The new toolbar will appear directly to the right of the Customize window — now drag it up to the top toolbar
- Now click on the Commands tab of the Customize window and select the Macros category:
- Select the MyMacros.GuidModule.InsertGUID command and drag it up to the Guid toolbar
- Right-click on the button and change the name to "Guid"
- Click Close on the Customize window and you’re done
Now, try it out by positioning the cursor somewhere in a text file that you need a new GUID to be inserted and press the Guid button. The first click takes a second or so to load the macro engine.
Bam! I love the smell of freshly-picked GUIDs. They’re so……unique. (Sorry, that was really bad.)
Hope that helps!
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
November 3rd, 2008 at 2:26 am
hi there mate,
I like what you have tried to achieve here. There is however a considerably easier solution to this problem. Check out this.
http://www.wintellect.com/CS/blogs/jrobbins/archive/2008/07/11/paraffin-1-04-a-new-switch-and-easier-updates.aspx