Profile photo
Submitted by Sunil Sharma
on June 21st, 2011 at 14:32:57 EST

NAnt and access Perforce files

Hi I have .NET application and I am using Perforce as our source control. Now, I am trying to integrate our source code to automated build using NAnt. I can not find any built in function in NAnt to access Perforce file. How to I interact with Perforce using NAnt?

Profile photo
Replied by RaKumar
on June 21st, 2011 at 14:42:39 EST
One way is to use NAnt Contrib. This is extended version of original NAnt. NAnt contrib supports Perforce as built-in task.
Url for NAnt contrib:
Then you can use Perforce specific tasks like "p4sync" to get list of file etc.

You can not however pass the password in here. I think its because of security, for password you would need to set P4PASSWORD. you can set Perforce P4PASSWD environment password using "p4 passwd" command.

Another way is to use original NAnt and use <exec> task to execute perforce P4 command.
For example:
<!--Task for getting lastest source code from Perforce.-->
<property name="perforce.dir" value="C:\Program Files\Perforce" />
<property name="project.depot" value="&quot;//MyPerforceDepot/MyApplication&quot;" />
<property name="perforce.g-opts" value="-p PerforceServer:1666 -c BuildLocal -u UserName -P Password" />
<target name="GetSourceCodeFromPerforce" description="Get latest sourcecode from Perforce">
<exec basedir="${perforce.dir}" workingdir="${perforce.dir}" program="p4" commandline="${perforce.g-opts} sync -f ${project.depot}/..." failonerror="true" />
Accepted Answer

Profile photo
Replied by Sunil Sharma
on June 21st, 2011 at 14:51:00 EST
Thanks. That works. I liked both of your solutions. Cooooool.

Profile photo
on July 31st, 2012 at 06:50:14 EST
I am not able to use both the commands, could you plz let me know what is -c BuildLocal option in the above command.

First command gives the error:
[p4sync] //depot/development/views/9/1/top/product - no such file(s).

Profile photo
Replied by SBajra
on July 31st, 2012 at 12:06:49 EST
-c BuildLocal, where BuildLocal is name of Perforce workspace.