Summary
- Assembly
- NAnt
.Core .dll - Namespace
- NAnt
.Core .Tasks - Interfaces
- Base Types
- Derived Types
Syntax
[TaskName("copy")]
public class CopyTask : Task, IConditional
Examples
Copy a single file while changing its encoding from "latin1" to "utf-8".
<copy
file="myfile.txt"
tofile="mycopy.txt"
inputencoding="latin1"
outputencoding="utf-8" />
Copy a set of files to a new directory.
<copy todir="${build.dir}">
<fileset basedir="bin">
<include name="*.dll" />
</fileset>
</copy>
Copy a set of files to a directory, replacing @TITLE@
with
"Foo Bar" in all files.
<copy todir="../backup/dir">
<fileset basedir="src_dir">
<include name="**/*" />
</fileset>
<filterchain>
<replacetokens>
<token key="TITLE" value="Foo Bar" />
</replacetokens>
</filterchain>
</copy>
Copy an entire directory and its contents.
<copy tofile="target/dir">
<fileset basedir="source/dir"/>
</copy>
Remarks
Files are only copied if the source file is newer than the destination
file, or if the destination file does not exist. However, you can
explicitly overwrite files with the NAnt.Core.Tasks.CopyTask.Overwrite
attribute.
When a NAnt.Core.Types.FileSet
is used to select files to copy, the
NAnt.Core.Tasks.CopyTask.ToDirectory
attribute must be set. Files that are
located under the base directory of the NAnt.Core.Types.FileSet
will
be copied to a directory under the destination directory matching the
path relative to the base directory of the NAnt.Core.Types.FileSet
,
unless the NAnt.Core.Tasks.CopyTask.Flatten
attribute is set to
true
.
Files that are not located under the the base directory of the
NAnt.Core.Types.FileSet
will be copied directly under to the destination
directory, regardless of the value of the NAnt.Core.Tasks.CopyTask.Flatten
attribute.
Encoding
Unless an encoding is specified, the encoding associated with the system's current ANSI code page is used.
An UTF-8, little-endian Unicode, and big-endian Unicode encoded text file is automatically recognized, if the file starts with the appropriate byte order marks.
Attributes
Type | Description |
---|---|
TaskNameAttribute | Indicates that class should be treated as a task. |
Constructors
Name | Summary |
---|---|
CopyTask |
Initialize new instance of the NAnt.Core.Tasks.CopyTask .
|
Properties
Name | Value | Summary |
---|---|---|
CopyFileSet | FileSet |
Used to select the files to copy. To use a
NAnt.Core.Types.FileSet ,
the NAnt.Core.Tasks.CopyTask.ToDirectory attribute must be set.
|
CustomXmlProcessing | bool |
Gets a value indicating whether the element is performing additional
processing using the
NAnt.Core.Element.XmlNode that was used to
initialize the element.
Inherited from Element
|
DirectoryCount | long |
Gets the number of directories that will be affected during the file
operation.
|
FailOnError | bool |
Determines if task failure stops the build, or is just reported.
The default is
true .
Inherited from Task
|
FileCopyMap | Hashtable |
The set of files to perform a file operation on.
|
FileCount | long |
Gets the number of files that will be affected during the file operation.
|
Filters | FilterChain |
Chain of filters used to alter the file's content as it is copied.
|
Flatten | bool |
Ignore directory structure of source directory, copy all files into
a single directory, specified by the
NAnt.Core.Tasks.CopyTask.ToDirectory
attribute. The default is false .
|
IfDefined | bool |
If
true then the task will be executed; otherwise,
skipped. The default is true .
Inherited from Task
|
IncludeEmptyDirs | bool |
Copy any empty directories included in the
NAnt.Core.Types.FileSet .
The default is true .
|
InputEncoding | Encoding |
The encoding to use when reading files. The default is the system's
current ANSI code page.
|
Location | Location |
Gets or sets the location in the build file where the element is
defined.
Inherited from Element
|
LogPrefix | string |
The prefix used when sending messages to the log.
Inherited from Task
|
Name | string |
The name of the task.
Inherited from Task
|
NamespaceManager | XmlNamespaceManager |
Gets or sets the
System.Xml.XmlNamespaceManager .
Inherited from Element
|
OutputEncoding | Encoding |
The encoding to use when writing the files. The default is
the encoding of the input file.
|
Overwrite | bool |
Overwrite existing files even if the destination files are newer.
The default is
false .
|
Parent | Object |
Gets or sets the parent of the element.
Inherited from Element
|
Project | Project |
Gets or sets the
NAnt.Core.Element.Project to which this element belongs.
Inherited from Element
|
Properties | PropertyDictionary |
Gets the properties local to this
NAnt.Core.Element and the
NAnt.Core.Element.Project .
Inherited from Element
|
SourceFile | FileInfo |
The file to copy.
|
Threshold | Level |
Gets or sets the log threshold for this
NAnt.Core.Task . By
default the threshold of a task is NAnt.Core.Level.Debug ,
causing no messages to be filtered in the task itself.
Inherited from Task
|
ToDirectory | DirectoryInfo |
The directory to copy to.
|
ToFile | FileInfo |
The file to copy to.
|
UnlessDefined | bool |
Opposite of
NAnt.Core.Task.IfDefined . If false
then the task will be executed; otherwise, skipped. The default is
false .
Inherited from Task
|
Verbose | bool |
Determines whether the task should report detailed build log messages.
The default is
false .
Inherited from Task
|
XmlNode | XmlNode |
Gets or sets the XML node of the element.
Inherited from Element
|
Methods
Name | Value | Summary |
---|---|---|
CopyTo |
void |
Copies all instance data of the
NAnt.Core.Element to a given
NAnt.Core.Element .
Inherited from Element
|
Create |
BuildException |
Creates a source file not found exception.
|
DoFileOperations |
void |
Actually does the file copies.
|
Execute |
void |
Executes the task unless it is skipped.
Inherited from Task
|
ExecuteTask |
void |
Executes the Copy task.
|
Get |
XmlNode |
Locates the XML node for the specified attribute in either the
configuration section of the extension assembly or the.project.
Inherited from Task
|
Get |
XmlNode |
Inherited from Element
|
GetLocation |
Location |
Retrieves the location in the build file where the element is
defined.
Inherited from Element
|
Initialize |
void |
Checks whether the task is initialized with valid attributes.
|
Initialize |
void |
Performs default initialization.
Inherited from Element
|
Initialize |
Element |
Initializes the build element.
Inherited from Element
static
|
InitializeElement |
void |
Derived classes should override to this method to provide extra
initialization and validation not covered by the base class.
Inherited from Element
|
InitializeTask |
void |
Initializes the task.
Inherited from Task
|
Initialize |
void |
Initializes the configuration of the task using configuration
settings retrieved from the NAnt configuration file.
Inherited from Task
|
InitializeXml |
void |
Initializes all build attributes and child elements.
Inherited from Element
|
IsLogEnabledFor |
bool |
Determines whether build output is enabled for the given
NAnt.Core.Level .
Inherited from Task
|
Log |
void |
Logs a message with the given priority.
Inherited from Task
|
Log |
void |
Logs a formatted message with the given priority.
Inherited from Task
|