如何在构建后事件中定义当前系统日期 [英] How to define current system date in post build event

查看:56
本文介绍了如何在构建后事件中定义当前系统日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 .dll 复制到格式为test\Project_yyyy.mm.dd"的目标目录中其中 yyyy - 当前年份,mm - 当前月份,dd - 当前日期.当我在构建后事件中给出以下命令时,出现错误.

I want to copy .dlls into a target directory of format "test\Project_yyyy.mm.dd" Where yyyy - cuurent year, mm - current month, dd - current date. When I give the below command in my post build event, I am getting an error.

xcopy /Y "$(TargetDir)*.*" test\Project_$(Year:yyyy).$(Month).$(DayOfMonth)

我找不到任何定义当前日期的宏.有人可以帮我解决这个问题.

I could not find any macro which define current date. Can someone please help me on this.

推荐答案

您可以使用 MSBuild 属性函数 调用一些 .Net API.您可以使用 System.DateTime.Now 获取当前时间,然后获取年/月/日作为此对象的属性.

You can use MSBuild Property Functions to call some of the .Net API. You can use System.DateTime.Now to obtain current time, then fetch year/month/day as properties of this object.

这是执行此操作的代码:

Here is a code that does this:

<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <CurrentYear>$([System.DateTime]::Now.Year)</CurrentYear>
    <CurrentMonth>$([System.DateTime]::Now.Month)</CurrentMonth>
    <CurrentDay>$([System.DateTime]::Now.Day)</CurrentDay>
  </PropertyGroup>

  <Target Name="Print">
    <Message Text="Year: $(CurrentYear)" />
    <Message Text="Month: $(CurrentMonth)" />
    <Message Text="Day: $(CurrentDay)" />
  </Target>
</Project>

这篇关于如何在构建后事件中定义当前系统日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆