How to replace string in a file using NANT

nant

I am trying to replace the occurance of a string in a wxs file using Nant.

I have only found the following example, which uses <replaceString>, but it seems like it can only be used within the copied files. Are there any other way of replacing a string, without actually copying the files over?

<property name="NOW" value="${datetime::now()}" />
<copy todir="out">
    <fileset basedir="in">
        <include name="**/*" />
    </fileset>
    <filterchain>
        <replacetokens>
            <token key="NOW" value="${TODAY}" />
        </replacetokens>
        <tabstospaces />
    </filterchain>
</copy>

Best Answer

Here's the code:

<loadfile file="token.txt" property="token-file">
    <filterchain>
        <replacetokens>
            <token key="NOW" value="${datetime::now()}" />
        </replacetokens>
    </filterchain>
</loadfile>

The official NAnt docs for <loadfile> element contain the exact sample you need. See the bottom of the page.

Related Topic