.NET Framework Bookmark and Share   
 index > MSBuild > Create a release directory based on current timestamp
 

Create a release directory based on current timestamp

Hi all,
I'm migrating a powershell build script to a MS Build file and integrated with Teamcity and I'm nearly done. Our deployment performs a build in Release configuration, then copies everything in to a set directory. Currently for testing I've just set my variables up as follows.

<PropertyGroup>
    <Configuration>Release</Configuration>
    <ReleaseDir>Release</ReleaseDir>
  </PropertyGroup>
What I really need is to set my $(ReleaseDir) variable to a directory with the following timestamp format.

Release\yyyymmddHHMMss

How can I create the string path above and get it into my $(ReleaseDir) path based on the current system time? I've searched online, and I also have the community build tasks installed, but I just can't seem to find any documentation on how to use the Time tag.

Thanks,
Todd
Todd Nine
I'm not sure about the community tasks. If you have .net 3.5 available, you can use the MSBuild Extension Pack tasks, e.g.

<MSBuild.ExtensionPack.Framework.DateAndTime TaskAction="Get" Format="yyyymmddHHMMss ">
<Output TaskParameter="Result" PropertyName="MyStartTime"/>
</MSBuild.ExtensionPack.Framework.DateAndTime>

Mike
  • Marked As Answer byTodd Nine Wednesday, September 02, 2009 10:46 PM
  •  
Mike Fourie
I'm not sure about the community tasks. If you have .net 3.5 available, you can use the MSBuild Extension Pack tasks, e.g.

<MSBuild.ExtensionPack.Framework.DateAndTime TaskAction="Get" Format="yyyymmddHHMMss ">
<Output TaskParameter="Result" PropertyName="MyStartTime"/>
</MSBuild.ExtensionPack.Framework.DateAndTime>

Mike
  • Marked As Answer byTodd Nine Wednesday, September 02, 2009 10:46 PM
  •  
Mike Fourie
Thanks for the reply. I've downloaded and installed the extensions as outlined in the documentation here.

http://www.msbuildextensionpack.com/help/3.5.3.0/index.html

I've also installed the schemas for IntelliSense. Unfortunately, whenever I run my build file, I receive the error below

\build.proj(10,5): error MSB5016: The name "MSBuild.ExtensionPack.Framework.DateAndTime" contains an invalid character ".".
Line 10 corresponds to my MSBuild.ExtensionPack.Framework.DateAndTime task definition line. Here are my import statements, any ideas what I'm doing wrong? I thought I'd included everything I needed, so this is a bit of a stumper for me. I've also tried removing the community task import in case there was a conflict, but this doesn't seem to help either.

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

  <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\MSBuild.ExtensionPack.tasks"/>
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
 
  
  <PropertyGroup>
    <MSBuild.ExtensionPack.Framework.DateAndTime TaskAction="Get" Format="yyyymmddHHMMss">
      <Output TaskParameter="Result" PropertyName="MyStartTime"/>
    </MSBuild.ExtensionPack.Framework.DateAndTime>
    
    
    <Configuration>Release</Configuration>
    <ReleaseDir>Release\$(MyStartTime)</ReleaseDir>
    <NCoverPath>Tools\NCover</NCoverPath>
    <NCoverExplorerPath>Tools\NCoverExplorer</NCoverExplorerPath>
    <AppToProfileExe>Tools\NUnit\nunit-console.exe</AppToProfileExe>
    
  </PropertyGroup>
....

</Project>


Thanks,
Todd
Todd Nine
I have resolved my above issue, but now have a newer one that I'm not sure how to fix. In the above problem, I couldn't use the DateTime property outside of a Target element. I had to change my Property and output definition to the following to get it running.

<Target Name="BundleArtifact" DependsOnTargets="BuildSolution">

    <MSBuild.ExtensionPack.Framework.DateAndTime TaskAction="Get" Format="yyyyMMddHHmmss">
      <Output TaskParameter="Result" PropertyName="BundleDate"/>
    </MSBuild.ExtensionPack.Framework.DateAndTime>


    <PropertyGroup>
      <ReleaseDir>$(ReleaseBaseDir)\$(BundleDate)</ReleaseDir>
    </PropertyGroup>

    <!-- remove our release directory and create a new one-->
    <RemoveDir Directories="$(ReleaseBaseDir)" />

...Do copy and cleanup here...

    <!-- Zip everything up-->
    <MSBuild.ExtensionPack.Compression.Zip TaskAction="Create" CompressPath="$(ReleaseDir)" RemoveRoot="$(ReleaseBaseDir)" ZipFileName="$(ReleaseDir).zip"/>

  </Target>
Now I receive the following errors when I run my zip task

(BundleArtifact target) -> Build.proj(153,5): error : FileNotFoundException: Could not load file or assembly 'vjslib, Version=2.0.0.0, Culture=neutral , PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I'm assuming it's because I don't have J# installed. I have .net 1.1, 2.0 and 3.5 installed, how do I get this library on to my system?
Todd Nine
Well, my 3rd reply to my own post :). I just installed the J# redistributable package from here

http://www.microsoft.com/DOWNLOADS/details.aspx?familyid=F72C74B3-ED0E-4AF8-AE63-2F0E42501BE1&displaylang=en

Problem solved. Thanks for pointing me in the right direction, your help was greatly appreciated.
Todd Nine

You can use google to search for other answers

Custom Search

More Threads

• warning PRJ0009 : Build log could not be opened for writing.
• Why does Exec not have
• newbie question, how to specify individual project configs at sln command line
• Custom task for EVC?
• Is there a way to set a compiles exe or assembly version?
• MSBuild & Visual Studio Integration
• Targets Skipped Because SN.EXE Does Not Affect File Dates
• Changing AssemblyInfoTask properties for a single csproj?
• single thread in msbuild
• How to update the Assembly version for the entire solution