Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a timestamp to TFSBuild.proj?

I have a TFSBuild.proj file and I need to add date/time logging for statistics i.e. which parts of the builds take the most time and where can we improve the process.

The build outputs the log to BuildLog.txt. I use the following tags to get custom messages in the BuildLog.txt file, but I need to add a timestamp to each message.

<Message Text="Debug: BeforeGet start: StartTimeGoesHere"></Message>
<Message Text="Debug: BeforeGet end: EndTimeGoesHere"></Message>

Is it possible to get a timestamp in the message? Is there a MSBuild variable that gets the current datetime value? In the example above, StartTimeGoesHere will be something like "01 Jan 2001 14:10:12" and EndTimeGoesHere will be something like "01 Jan 2001 14:14:43".

like image 904
Alicia Avatar asked Jun 27 '11 01:06

Alicia


2 Answers

You don't need any third party support as long as you are using MSBuild 4.0. Just use a property function within a target,

<PropertyGroup>
  <DateTimeNow>$([System.DateTime]::Now)</DateTimeNow>
</PropertyGroup>

which will create the following value for $(DateTimeNow),

6/26/2011 9:00:27 PM
like image 123
Brian Kretzler Avatar answered Nov 17 '22 03:11

Brian Kretzler


You need to use the MS Build Community Tasks. It has a Time task that will give you what you want.

http://msbuildtasks.tigris.org/

 <Time Format="yyyy-MM-dd hh:mm:ss">
    <Output TaskParameter="FormattedTime" PropertyName="currentTime" />
 </Time>

You will need to setup a start and end time and you will need to be careful about where you invoke the tasks.

like image 1
Jeff Avatar answered Nov 17 '22 04:11

Jeff