如何在Visual Studios的后置构建脚本中使用构建时间戳

5
在Visual Studio中以Release目标构建项目时,我希望将二进制文件复制到一个版本控制下的发布文件夹中。为了方便识别构建时间,应该添加一个形式为
__yyyy-MM-ddTHHmmss__
的时间戳文件。
3个回答

10

我使用了以下内容:

在我的项目文件开头,我添加了一个时间戳属性:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>

    <Timestamp>$([System.DateTime]::Now.ToString("yyyy-MM-dd\THHmmss"))</Timestamp>

    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

然后可以使用$(Timestamp)的后置构建事件:

<PostBuildEvent>
    if $(ConfigurationName) == Production (

    mkdir "$(SolutionDir)__RELEASE__\$(TargetName)"
    del /q "$(SolutionDir)__RELEASE__\$(TargetName)\*"

    echo $(Timestamp)&gt; "$(SolutionDir)__RELEASE__\$(TargetName)\__$(Timestamp)__"

    copy /Y "$(TargetDir)" "$(SolutionDir)__RELEASE__\$(TargetName)\"
    del /q "$(SolutionDir)__RELEASE__\$(TargetName)\*.tmp"
    del /q "$(SolutionDir)__RELEASE__\$(TargetName)\*.log"
    del /q "$(SolutionDir)__RELEASE__\$(TargetName)\*.err"

    TortoiseProc /command:add /path:"$(SolutionDir)__RELEASE__\"
  )
</PostBuildEvent>

0

如果有人偶然发现这个问题,这对我很有帮助:

<PropertyGroup>
    <Time>$([System.DateTime]::Now.ToString())</Time>
</PropertyGroup>
<Message Text="$(Time2)" Importance="High" />

0
如果有人仍在寻找此解决方案,可以在“后生成事件命令行”中键入Time /T。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接