Sunday, July 05, 2009

Generate (a new) GUID each time you run an MSBuild Script

Sometimes we need to generate a new GUID and use it as part of a build script, for example when building a new version of a Setup project.

MSBuild built-in tasks don’t provide such facility, however there 2 options:

1.MSBuild Community Tasks (Script Task)

The Script task from MSBuild Community Task allows the execution of .net code contained within the task. It will be very simple to call System.Guid.NewGuid() and return the string into an MSBuild Property.


      public static string ScriptMain() {
          return System.Guid.NewGuid().ToString().ToUpper();

<Script Language="C#" Code="$(GuidGenFunction)">
      <Output TaskParameter="ReturnValue" PropertyName="NewGuid" /> 
<Message Text="Guid: $(NewGuid)" />



2.Sedodream MSBuild Project (CreateGuid Task)

1 comment:

Anonymous said...

I found this very helpful, thanks!