有没有办法在MSBuild(版本3.5)中轻松输出当前时间?

发布于 2024-12-09 10:14:41 字数 1333 浏览 0 评论 0原文

我想在调用 MSBuild 3.5 时输出当前时间(最好在每个任务之前或至少在开始/完成每个目标时)。

我尝试创建一个我会不断调用的目标,如下所示:

<Target Name="EchoTime">
    <Time Format="yyyy-MM-dd HH:mm:ss.fff">
        <Output TaskParameter="FormattedTime" PropertyName="currentTime" />
    </Time>
    <Message Text = "$(currentTime)" />
</Target>

...但事实证明,一个目标每次执行只能调用另一个目标一次。

所以如果我尝试...

<Target Name="TimeTest" >
    <Message Text = "--------------------------------------------------" />
    <CallTarget Targets="EchoTime" />
    <Message Text = " " />
    <Message Text = "Try calling EchoTime again" />
    <Message Text = " " />
    <CallTarget Targets="EchoTime" />
    <Message Text = "--------------------------------------------------" />
</Target>

那么输出看起来像...

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)).

有人知道实现此目的的简单方法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗恋未遂 2024-12-16 10:14:41

CallTarget 无法执行同一目标两次,但有一个 解决方法

<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>

请注意,为每个后续调用将 prop1 的值设置为不同的值。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文