MSBuild MSBuildCommunityTasks Task Time

2020-02-25 08:02发布

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.

3条回答
来,给爷笑一个
2楼-- · 2020-02-25 08:26

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 '

查看更多
做个烂人
3楼-- · 2020-02-25 08:28

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

查看更多
太酷不给撩
4楼-- · 2020-02-25 08:43
<?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>
查看更多
登录 后发表回答