Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use build timestamp in Visual Studios post build script

When building a project in Visual Studio at the Release target, I want to copy my binaries to a release folder which is under version control. To easily recognize the build time, a timestamp file in the form

__yyyy-MM-ddTHHmmss__

should be added.

like image 434
abto Avatar asked Jun 11 '14 17:06

abto


1 Answers

I used the following:

At the beginning of my project file I added a timestamp property:

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

Then one can use a postbuild event with $(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>
like image 173
abto Avatar answered Nov 09 '22 20:11

abto