Update Version Number in a File.

September 23rd, 2009 § 0 comments § permalink

No, not an AssemblyInfo.cs file, that’s really straightforward. C’mon it’s a task that does what it says, easy.

Something I was trying to do is update the version number in, for all simple purposes, a text file – something that’s not xmlpoke-able. So I have the property ready to go and the file I want to update!

My first thoughts were to use the loadfile to get the file into a property and replace it with the version.

<loadfile file=”some.txt” property=”token-file”>

<filterchain>

<replacetokens>

<token key=”VERSION” value=”${version}” />

</replacetokens>

</filterchain>

</loadfile>

Awesome, just like the sample and it echos out just fine…so now, how do I save my changes? After some digging around, I looked into the filterchain and read up on the copy task.

Seriously, copying a file now has the ability to modify the internals? Does not compute! Maybe copy, then modify. Anyway, its works now, so I can’t really complain anymore besides the hassle of finding the right task to do the job.

<copy file=”some-template.txt” tofile=”some.txt”>

<filterchain>

<replacetokens>

<token key=”VERSION” value=”${version}” />

</replacetokens>

</filterchain>

</copy>

Now I know why James keeps telling me to get out of the XML HELL. Coding tasks in XML is just ass backwards.

Where am I?

You are currently viewing the archives for September, 2009 at thomas nguyen.