MSBuild MSBuildCommunityTasks 任务时间

发布于 2024-07-20 07:26:55 字数 429 浏览 6 评论 0原文

我有一个 MSBuild 项目,我希望将当前日期添加到我正在创建的 zip 文件中。

我正在使用 MSBuildCommunityTasks。

<!-- Import the CommunityTasks Helpper -->
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />

在网站 http://msbuildtasks.tigris.org/ 上,我可以看到一个名为 time 的任务。 我无法找到有关如何使用时间的文档。

I have a MSBuild project and I want the current date to be added to a zip file that I am creating.

I am using the MSBuildCommunityTasks.

<!-- Import the CommunityTasks Helpper -->
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />

On the website http://msbuildtasks.tigris.org/ I can see a task called time. I have not been able to find doc on how to use Time.

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

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

发布评论

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

评论(3

思慕 2024-07-27 07:26:55

在 msbuild 4 中,您现在可以

$([Namespace.Type]::Method(..parameters…))
$([Namespace.Type]::Property)
$([Namespace.Type]::set_Property(value))

使用的那些勾号是反引号而不是 '

$([System.DateTime]::Now.ToString(`yyyy.MMdd`))

所以我在格式周围

In msbuild 4 you can now

$([Namespace.Type]::Method(..parameters…))
$([Namespace.Type]::Property)
$([Namespace.Type]::set_Property(value))

so I am using

$([System.DateTime]::Now.ToString(`yyyy.MMdd`))

those ticks around the format are backticks not '

等待我真够勒 2024-07-27 07:26:55
<?xml version="1.0" encoding="utf-8"?>

<Project DefaultTargets="Deploy" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

  <!-- Include MSBuild tasks here -->

  <ItemGroup>     
      <DefaultExclude Include="****" />           
  </ItemGroup>


 <Target Name="Deploy" >

    <Time Format="yyyy-MM-dd">
    <Output TaskParameter="FormattedTime" PropertyName="buildDate" />
    </Time>

    <Message Text="Deploying ...."></Message>   

    <Copy  SourceFiles="@(DeploymentFiles)" DestinationFolder="C:\CCNET\$(buildDate)\bin\" />

</Target>

</Project>
<?xml version="1.0" encoding="utf-8"?>

<Project DefaultTargets="Deploy" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

  <!-- Include MSBuild tasks here -->

  <ItemGroup>     
      <DefaultExclude Include="****" />           
  </ItemGroup>


 <Target Name="Deploy" >

    <Time Format="yyyy-MM-dd">
    <Output TaskParameter="FormattedTime" PropertyName="buildDate" />
    </Time>

    <Message Text="Deploying ...."></Message>   

    <Copy  SourceFiles="@(DeploymentFiles)" DestinationFolder="C:\CCNET\$(buildDate)\bin\" />

</Target>

</Project>
半城柳色半声笛 2024-07-27 07:26:55

马斯洛的答案是正确的(我不能对此发表评论,或者我会); 我只想补充一点,在隐式调用 System.DateTime.Parse 时必须小心。

$([System.DateTime]::Parse("1970-01-01T00:00:00.0000000Z") 这样的解析字符串值似乎不会以某种 结尾DateTimeKind.Utc

但您可以使用嵌套属性函数 使其工作;像这样(获取 Unix 时间戳):

$([System.DateTime]::UtcNow.Subtract($([System.DateTime]::Parse("1970-01-01T00 :00:00.0000000Z").ToUniversalTime())).TotalSeconds.ToString("F0"))

Maslow's answer is correct (I can't comment on it or I would); I would only add to it that you have to be careful when implicitly calling System.DateTime.Parse.

A parsed string value like $([System.DateTime]::Parse("1970-01-01T00:00:00.0000000Z") doesn't seem to end up with a Kind of DateTimeKind.Utc.

But you can use nested property functions to make it work; like this (to get the Unix timestamp):

$([System.DateTime]::UtcNow.Subtract($([System.DateTime]::Parse("1970-01-01T00:00:00.0000000Z").ToUniversalTime())).TotalSeconds.ToString("F0"))

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