date format in msbuild script?

Goran picture Goran · Jan 22, 2010 · Viewed 7.7k times · Source

In my msbuild script I'm creating a zip file with year/month/day in the zip filename, but month and day are always written with no leading zero.

Is there a way to add leading zero to my zip filename?

<Time>
  <Output TaskParameter="Year" PropertyName="Year" />
  <Output TaskParameter="Month" PropertyName="Month" />
  <Output TaskParameter="Day" PropertyName="Day" />
</Time>

<PropertyGroup>
  <ZipOutDir>C:\output</ZipOutDir>
  <ZipFileName>Application_$(Year)$(Month)$(Day).zip</ZipFileName>
</PropertyGroup>

And the result is: 'Application_2010122.zip' (with no leading zero for january, as you can see)

Answer

Maslow picture Maslow · Jul 11, 2011

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 '