Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace string in a file using NANT?

Tags:

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>
like image 767
RKM Avatar asked Dec 19 '11 15:12

RKM


3 Answers

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.

like image 98
Yan Sklyarenko Avatar answered Nov 03 '22 18:11

Yan Sklyarenko


Here's how I did it.

<loadfile file="${file}" property="file.content">
    <filterchain>
        <replacestring from="StringToMatch" to="StringToReplace" ignorecase="true" />
    </filterchain>
</loadfile>
<echo file="${file}">${file.content}</echo>
like image 35
Ally Avatar answered Nov 03 '22 20:11

Ally


So you are trying to modify a .wxs file which is XML, right?

In this particular case you might use <xmlpoke> if you are able to determine the position of the strings to replace via XPath.

like image 37
The Chairman Avatar answered Nov 03 '22 20:11

The Chairman