How to use C# inside nant build scripts
I use c# to take input from user (via command line) to take certain actions in build script. Here’s code that ask name of web app and will copy necessery files to target directories.
<target name=”AskAndDeploy”>
<script language=”C#” prefix=”DNSNamePrefix” >
<code><![CDATA[
[Function(“ask”)]
public string AskDNSNamePrefix(string prompt) {
Project.Log(Level.Info, prompt);
try
{
return Console.ReadLine();
}
finally
{
}
}
]]></code>
</script>
<echo message=”If Your website is called foo.dev.co.uk then enter foo as DNS Prefix. Config files will be updated to point AT http://foo.dev.co.uk ” />
<property name=”DNSNamePrefix” value=”${DNSNamePrefix::ask(‘What is the web DNS name prefix ?’)}” />
<property name=”Build.Env.Name” value=”qa” />
<property name=”Solution.Dir.Path” value=”C:\Projects\phoenix” />
<copy todir=”\appqawin\projects\${DNSNamePrefix}WS.qa">
<fileset basedir=”${Solution.Dir.Path}\src\JB.WebService">
<include name=”**\*”/>
<exclude name=”**/bin/JB.Common.config” />
</fileset>
</copy>
</target>