CreateGuid MSBuild Task

There doesn’t seem to be a way to create GUIDs out-of-the-box in MSBuild or through the MSBuild community tasks, so I created a custom task to do it for you.

Usage:

<!–

This task creates a new GUID using System.Guid.NewGuid()

The Format parameter is optional. If specified it must be one of “N” “D” “B” “P” “”. Default is “D”

See http://msdn2.microsoft.com/en-us/library/s6tk2z69.aspx for more information.

N = 32 digits: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
D = 32 digits separated by hyphens: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
B = 32 digits separated by hyphens, enclosed in brackets: {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
P = 32 digits separated by hyphens, enclosed in parentheses: (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

–>

<CreateGuid Format=”D”>
    <Output TaskParameter=”Output” PropertyName=”MyGuid” />
</CreateGuid>

<Message Text=”Guid: $(MyGuid)” />

Download:

Download CreateGuid.cs.txt

2 Comments

  1. Posted April 5, 2008 at 12:38 am | Permalink

    Hi,
    Do you mind If I add this to my open source project at http://www.codeplex.com/sedodream?

    Sayed Ibrahim Hashimi

  2. Posted July 5, 2009 at 6:14 am | Permalink

    You could use MSBuild community tasks Script task to call the System.Guid.NewGuid() and return the string into a property

    Example from the documentation:


One Trackback

  1. By Team System News : VSTS Links - 04/09/2008 on April 10, 2008 at 12:48 am

    [...] Holliday on CreateGuid MSBuild Task, TFS Deployer Patches and Windows Explorer TFS Client with [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*