Reputation: 1405
I'd like to output the current time (preferably before every task or at minimum when starting/completing every target) when invoking MSBuild 3.5.
I tried creating a target that I would continually call that looks like:
<Target Name="EchoTime">
<Time Format="yyyy-MM-dd HH:mm:ss.fff">
<Output TaskParameter="FormattedTime" PropertyName="currentTime" />
</Time>
<Message Text = "$(currentTime)" />
</Target>
...but it turns out that one target can only call another target once per execution.
So if I try...
<Target Name="TimeTest" >
<Message Text = "--------------------------------------------------" />
<CallTarget Targets="EchoTime" />
<Message Text = " " />
<Message Text = "Try calling EchoTime again" />
<Message Text = " " />
<CallTarget Targets="EchoTime" />
<Message Text = "--------------------------------------------------" />
</Target>
Then the output looks like...
Build started 10/12/2011 2:24:52 PM.
Project "C:\Temp\MSBuildSandbox\MSBuild_EchoTime.xml" on node 0 (TimeTest target(s)).
--------------------------------------------------
EchoTime:
2011-10-12 14:24:52.756
TimeTest:
Try calling EchoTime again
--------------------------------------------------
Done Building Project "C:\Temp\MSBuildSandbox\MSBuild_EchoTime.xml" (TimeTest target(s)).
Anyone know an easy way to achieve this?
Upvotes: 2
Views: 1319
Reputation: 18061
CallTarget
cannot execute the same target twice but there's a workaround using the MSBuild
task:
<Target Name="TimeTest" >
<Message Text = "--------------------------------------------------" />
<MSBuild
Targets="EchoTime"
Projects="$(MSBuildProjectFile)"
Properties="prop1=val1"
/>
<Message Text = " " />
<Message Text = "Try calling EchoTime again" />
<Message Text = " " />
<MSBuild
Targets="EchoTime"
Projects="$(MSBuildProjectFile)"
Properties="prop1=val2"
/>
<Message Text = "--------------------------------------------------" />
</Target>
Note setting the value for prop1
to a different value for each subsequent call.
Upvotes: 2