xmlbuildcommand-promptnantxcopy

How to use XCopy in a build script instead of copy in Windows


Earlier to deploy my dot-net project into my remote server I was using copy command in a nant build configuration file. The command is shown below.

<target name="Deploy">
    <copy  todir="${path.to.the.directory}" overwrite="true">
        <fileset basedir="${Bin.Path}">
            <include name="*.*" />          
        </fileset>
    </copy>
</target>

Now as my project grew I got two new folders inside my $[bin.path] folder and now I cannot use copy command to copy my executable to the output folder.

What can I do?

After searching I found out I can use XCopy. But I am not getting how to integrate that into my build script similar to the one shown above.


Solution

  • I wonder why you came to a conclusion that you can't use <copy> task.

    If you need to include the subfolders into the copy set, change your NAnt script to this:

    <target name="Deploy">
        <copy  todir="${path.to.the.directory}" overwrite="true">
            <fileset basedir="${Bin.Path}">
                <include name="**\*.*" />          
            </fileset>
        </copy>
    </target>
    

    If you don't want to keep the folder structure in the target directory, you can use flatten attribute of <copy> task:

    <target name="Deploy">
        <copy  todir="${path.to.the.directory}" overwrite="true" flatten="true">
            <fileset basedir="${Bin.Path}">
                <include name="**\*.*" />          
            </fileset>
        </copy>
    </target>
    

    Hope this helps.