Link to home
Start Free TrialLog in
Avatar of Rohde
Rohde

asked on

Problem with NAnt build (can't get filterchain to work)

I'm trying setting up a build-script in Nant (and I'm somewhat of a "NAnt-noob").
In this script I want to copy my entire codebase to a temporary directory, in which I later compile the code. When doing this copy, I want to replace certain keywords in the sourcecode, and for that I'm using "filterchain"s.
The copy works fine, but the filterchain doesn't seem to be executed at all.

Does anyone have any pointers?

I have included the content of my attempts so far in this post. This is of course not my real build, just a mock-up I made to try and isolate the problem (also downloadable from http://openspace.subsero.dk/temp/nant_problem.zip).

The setup is:
---------------
NAnt 0.84 (Build 0.84.1455.0; net-1.0.win32; release; 26-12-2003)

The buildfile:
---------------
<?xml version="1.0"?>
<project name="Deploysource" default="deploysource" basedir=".">
            <property name="ApplicationName" value="MyApplication" />


            <target name="deploysource">
                        <copy file="source/testfile.cs" tofile="target/testfile.cs" inputencoding="utf-8" outputencoding="utf-8">
                                    <filterchain>
                                          <replacestring from="String" to="System.String" ignorecase="true" />
                                          <replacestring from="appName" to="${ApplicationName}" ignorecase="true" />
                                    </filterchain>
                        </copy>
            </target>
</project>


The source file:
---------------
//you are looking at appName

protected String testString = "hello";
Avatar of Rohde
Rohde

ASKER

Does anyone have an existing NAnt buildscript (which uses filterchain in some form) that they could post or mail me?
That way I would have a working example which I could manipulate to fit my setup. (I can't find any in the samples that come with NAnt)
http://nant.sourceforge.net/release/0.85-rc1/sdk/NAnt.Core.Filters.FilterChain.html
(taken from above link)
" Replace all occurrences of @NOW@ with the current date/time and replace tabs with spaces in all copied files."
<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>

http://weblogs.asp.net/soever/archive/2005/03/17/394985.aspx
(taken from above link)
<project default="go">
<target name="go">
<property name="word" value="nice" />
<loadfile file="input.txt" property="message">
<filterchain>
<replacetokens = "WORD" value="${word}" />
</filterchain>
</loadfile>
<echo message="${message}" />
</target>
</project>

Hope that helps!
Avatar of Rohde

ASKER

Thanks Mudie,
Not your fault of course - but none of the examples worked :o)

crash:
<replacetokens = "WORD" value="${word}" />

property name should be TODAY:
<property name="NOW" value="${datetime::now()}" />
.....
<token key="NOW" value="${TODAY}" />

But never mind - when fixed, they both work.... the weird thing is that now my original sample (http://openspace.subsero.dk/temp/nant_problem.zip) also works !
I think it was propably a version issue. Filterchain is a 0.85 addition and I was using 0.84, but even after upgrading, it still didn't work. Quite weird, but I'm happy it works now :-)

I'm willing to give you partial credit for your effort Mudie, if someone can tell me how. In the faq it says "click the 'Split Points' link", but I can't see any such link.


ASKER CERTIFIED SOLUTION
Avatar of Mudie
Mudie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial