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.
<PropertyGroup>
<GuidGenFunction>
<![CDATA[
public static string ScriptMain() {
return System.Guid.NewGuid().ToString().ToUpper();
}
]]>
</GuidGenFunction>
</PropertyGroup>
<Script Language="C#" Code="$(GuidGenFunction)">
<Output TaskParameter="ReturnValue" PropertyName="NewGuid" />
</Script>
<Message Text="Guid: $(NewGuid)" />
2.Sedodream MSBuild Project (CreateGuid Task)
http://sedodream.codeplex.com/Wiki/View.aspx?title=CreateGuid
1 comment:
I found this very helpful, thanks!
Post a Comment