I've been using NAnt a lot lately for deploying components to development and integration machines. The common misconception that I've heard from reluctant SharePoint folks around here is that we should be packaging SharePoint solutions in WSP (SharePoint solution files) instead of deploying components with NAnt. That's all great, I'm totally pro-WSP and all, but the thing people don't realize is that whether or not you're using WSP files, NAnt still compliments SharePoint deployments very well.
Even if I'm simply running STSADM commands, I would still use NAnt instead of writing batch files. NAnt can do so much more than WSP files are capable of doing such as: Modifying data in Web.Config files (xmlpeek/xmlpoke), creating Virtual Directories on your IIS site (mkiisdir), copying files (copy), etc.
One use I've found for NAnt is to deploy an InfoPath 2007 form to Central Administration and activate to my site collections, and adding Data Connection Library (.udcx) files to Central Administration. It was always a hassle to do that manually, and batch files are so 1980's.
So here is some NAnt XML that I've written to deploy InfoPath forms and Data Connections:
<property name="stsadm.exe" value="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\STSADM.exe" />
<target name="DeployInfoPathForms" description="Deploys the InfoPath forms to SharePoint">
<property name="formName" value="MyInfoPathForm.xsn" />
<call target="DeployForm" />
<exec program="IISRESET" />
</target>
<target name="DeployForm" description="Deploys an InfoPath form">
<exec program="${stsadm.exe}" failonerror="false">
<arg line="-o deactivateformtemplate" />
<arg line="-url http://mysharepointsite" />
<arg line="-filename ".\PublishedForms\${formName}"" />
</exec>
<exec program="${stsadm.exe}" failonerror="false">
<arg line="-o removeformtemplate" />
<arg line="-filename ".\PublishedForms\${formName}"" />
</exec>
<exec program="${stsadm.exe}" failonerror="false">
<arg line="-o execadmsvcjobs" />
</exec>
<exec program="${stsadm.exe}">
<arg line="-o uploadformtemplate" />
<arg line="-filename ".PublishedForms\${formName}"" />
</exec>
<exec program="${stsadm.exe}">
<arg line="-o execadmsvcjobs" />
</exec>
<exec program="${stsadm.exe}">
<arg line="-o activateformtemplate" />
<arg line="-url http://mysharepointsite "/>
<arg line="-filename ".PublishedForms\${formName}"" />
</exec>
</target>
<target name="DeployDataConnections" description="Deploys Forms Services Data Connection library files">
<property name="dataConnectionPath" value=".\config\DataConnections" />
<property name="dataConnectionFile" value="MyDataConnection.udcx" />
<call target="DeployDataConnection" />
</target>
<target name="DeployDataConnection" description="Deploys a single data connection">
<copy file="${dataConnectionPath}\${dataConnectionFile}" tofile=".\${dataConnectionFile}" />
<attrib file="${rootPath}\${dataConnectionFile}" readonly="false" />
<exec program="${stsadm.exe}">
<arg line="-o adddataconnectionfile" />
<arg line="-filename ".\${dataConnectionFile}"" />
<arg line="-overwrite true"/>
</exec>
<delete file=".\${dataConnectionFile}" />
</target>
You’ll notice I had to make a copy of the data connection before I could deploy it. This is because the file was read only when it’s checked in source control, so I needed to make a copy and take off the read only attribute using the NAnt attrib task before I could upload the file (Otherwise STSADM will complain).
Now you can call NAnt to deploy all of your forms at once, or you could specify an individual form by calling: “nant.bat –DeployForm –D:formName=MyFormName.xsn” or “nant.bat –DeployDataConnection –D:dataConnectionFile=MyDataConnection.udcx”.
Happy NAnting!