maonet technotes

IOC(SM):MOC(RM):TDD(NU):SCC(TFS):ORM(L2S):JSL(Jq):CIS(CC)

Replace file content in NAnt task

Posted by Frank Mao on August 12, 2008

As JP suggested, I always compile all my layered projects into a huge dll to make NAnt build file eaiser. This solution is perfect until I tried to embeb structuremap config file into cruise control. Because assembly file name changed, I have to find a way to replace the config file content in NAnt.

It was not easy. NAnt doesn’t have a replace task!

I don’t want hack into NAnt source to re-build my own version. It seems Jay Flowers, the creator of CI Factory has his modified version of NAnt which has replace task in it, but, no document to direct me how to use it.

OK, I have to call Ant task in NAnt build file then.

[NAnt build file]
<exec program=”c:\ant\bin\ant.bat” basedir=”${base.dir} “>
<arg value=”-Dcurrentproject.lib=${currentproject.lib}” />
</exec>

[Ant file]
<project name=”config” default=”replace_config” basedir=”.”>

<property name=”build.dir” value=”${basedir}\build”/>
<property name=”currentproject.lib” value=”undefined”/>

<target name=”replace_config”>
<replace file=”${build.dir}\StructureMap.config”>
<replacefilter token=”,mybizlayer” value=”,${currentproject.lib}”  />
<replacefilter token=”,mydatalayer” value=”,${currentproject.lib}”  />

</replace>

</target>
</project>

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>