Update your app VERSION using ant

This is just a quick tip in case someone needs it. Maybe when you compile your flash application or your swc library you want to automatically update the “VERSION” number too without do it manually every time.

This is the way I do. In the “compile” task I’ve added a depends link to this ant task:
<target name="update-version">
<propertyset id="tdate"></propertyset>
<tstamp>
<format property="tdate" pattern="yyyyMMdd"/>
</tstamp>
<buildnumber file="build.number"/>
<echo>updating version to current datetime: ${tdate}</echo>
<replaceregexp byline="true">
<regexp pattern="public static const BUILD_DATE: String = \'([0-9]+)'"/>
<substitution expression="public static const BUILD_DATE: String = '${tdate}'"/>
<fileset dir="src/it/sephiroth/somestuff">
<include name="Library.as"/>
</fileset>
</replaceregexp>
<replaceregexp byline="true">
<regexp pattern="public static const BUILD_NUMBER: String = \'([0-9\.]+)'"/>
<substitution expression="public static const BUILD_NUMBER: String = '${build.number}'"/>
<fileset dir="src/it/sephiroth/somestuff">
<include name="Library.as"/>
</fileset>
</replaceregexp>
</target>
The 2 optional tasks I’ve used are: BuildNumber task and ReplaceRegExp Task. In this way every time I do an ant compile, it will update my build number and modification date.
What this task does is find this 2 lines in my Library.as file:

public static const BUILD_DATE: String = ‘20100131’;

and

public static const BUILD_NUMBER: String = ‘5’;

then replace the BUILD_DATE const with the current date and the BUILD_NUMBER with an incremental build number. After being executed the first time, ant will also create a new file in your directory called “build.number” with the latest build number int.