using System; using System.Collections.Generic; using System.Text; using Microsoft.Build.Utilities; using Microsoft.Build.Framework; namespace Tools.MSBuildTasks { /// /// From: http://ozgrant.com/2008/04/04/createguid-msbuild-task/ /// /// This task creates a new GUID using System.Guid.NewGuid() /// /// The Format parameter is optional. /// /// /// /// /// /// /// /// /// /// public class CreateGuid : Task { /// /// The format specifier of the GUID. /// Must be one of "N" "D" "B" "P" "" /// Default is "D" /// /// 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) /// public String Format { get; set; } /// /// Outputs a new GUID in the default format: d36dda5f-1e18-4848-9407-2d733e8f680f /// [Output] public String Output { get; set; } public override bool Execute() { try { Output = Guid.NewGuid().ToString(Format); Log.LogMessage("GUID Created: {0}", Output); } catch (FormatException e) { Log.LogErrorFromException(e); return false; } return true; } } }