Building plugins with NAnt
April 8th, 2009
I’m a big fan of using convention to simplify your build process and its really easy to do. I’ll show that with a snippet from our NAnt build file which is a target that builds each of our plugins.
the convention I’m using is that
- each plugin is in folder named Something.Addin
- In order to compile each plugin into a seperate dll we use the foreach Task.
the property addin.name will contain just the folder name “Something.AddIn” instead of the absolute path that we get from the foreach Task.
I’m using Mono-Addins to provide plugin support to the application which I’ll cover soon.
<target name="-addin-compile">
<foreach item="Folder" property="folder">
<in>
<items>
<include name="${sources.dir}/*.addin"/>
</items>
</in>
<do>
<property name="index" value="${string::last-index-of(folder, '\')}"/>
<property name="addin.name" value="${string::substring(folder,int::parse(index)+1,string::get-length(folder)-int::parse(index)-1)}"/>
<echo message="Compiling ${addin.name}"/>
<csc target="library" output="${deploy.dir}/${addin.name}.dll" debug="false">
<sources>
<include name="${sources.dir}/${addin.name}/**/*.cs"/>
</sources>
<references>
<include name="System.Configuration.dll"/>
<include name="${deploy.dir}/mlb.aggregator.common.dll"/>
<include name="${lib.dir}/mono-addins/*.dll"/>
<include name="${lib.dir}/log4net/mono-3.5/log4net.dll"/>
<include name="${lib.dir}/xstream/*.dll"/>
<include name="${lib.dir}/nhibernate/*.dll"/>
</references>
</csc>
</do>
</foreach>
</target>
every project has conventions, not every project uses them