Summary
- Assembly
- NAnt
.Core .dll - Namespace
- NAnt
.Core .Types - Base Types
-
- Object
- Element
- DataTypeBase
Syntax
[ElementName("patternset")]
public class PatternSet : DataTypeBase
Examples
Define a set of patterns that matches all .cs files that do not contain
the text Test
in their name.
<patternset id="non.test.sources">
<include name="**/*.cs" />
<exclude name="**/*Test*" />
</patternset>
Define two sets. One holding C# sources, and one holding VB sources.
Both sets only include test sources when the test
property is
set. A third set combines both C# and VB sources.
<patternset id="cs.sources">
<include name="src/**/*.cs" />
<include name="test/**/*.cs" if=${property::exist('test')}" />
</patternset>
<patternset id="vb.sources">
<include name="src/**/*.vb" />
<include name="test/**/*.vb" if=${property::exist('test')}" />
</patternset>
<patternset id="all.sources">
<patternset refid="cs.sources" />
<patternset refid="vb.sources" />
</patternset>
Define a set from patterns in a file.
<patternset id="sources">
<includesfile name="test.sources" />
<includesfile name="non.test.sources" />
</patternset>
Defines a patternset with patterns that are loaded from an external file, and shows the behavior when that patternset is passed as a reference to a nested build script.
External file "c:\foo\build\service.lst" holding patterns of source files to include for the Foo.Service assembly:
AssemblyInfo.cs
*Channel.cs
ServiceFactory.cs
Main build script located in "c:\foo\default.build":
<project name="main" default="build">
<property name="build.debug" value="true" />
<patternset id="service.sources">
<include name="TraceListener.cs" if="${build.debug}" />
<includesfile name="build/service.lst" />
</patternset>
<property name="build.debug" value="false" />
<target name="build">
<nant buildfile="service/default.build" inheritrefs="true" />
</target>
</project>
Nested build script located in "c:\foo\services\default.build" which uses the patternset to feed sources files to the C# compiler:
<project name="service" default="build">
<target name="build">
<csc output="../bin/Foo.Service.dll" target="library">
<fileset basedir="src">
<patternset refid="service.sources" />
</fileset>
</csc>
</target>
</project>
At the time when the patternset is used in the "service" build script, the following source files in "c:\foo\services\src" match the defined patterns:
AssemblyInfo.cs
MsmqChannel.cs
SmtpChannel.cs
ServiceFactory.cs
TraceListener.cs
You should have observed that:
- although the patternset is used from the "service" build script, the path to the external file is resolved relative to the base directory of the "main" build script in which the patternset is defined.
- the "TraceListener.cs" file is included, even though the "build.debug" property was changed to false after the patternset was defined (but before it was passed to the nested build, and used).
Remarks
The individual patterns support if
and unless
attributes
to specify that the element should only be used if or unless a given
condition is met.
The NAnt.Core.Types.PatternSet.IncludesFile
and NAnt.Core.Types.PatternSet.ExcludesFile
elements load patterns from a file. When the file is a relative path,
it will be resolved relative to the project base directory in which
the patternset is defined. Each line of this file is taken to be a
pattern.
The number sign (#) as the first non-blank character in a line denotes that all text following it is a comment:
EventLog.cs
# requires Mono.Posix
SysLogEventLogImpl.cs
# uses the win32 eventlog API
Win32EventLogImpl.cs
Patterns can be grouped to sets, and later be referenced by their
NAnt.Core.DataTypeBase.ID
.
When used as a standalone element (global type), any properties that are referenced will be resolved when the definition is processed, not when it actually used. Passing a reference to a nested build file will not cause the properties to be re-evaluated.
To improve reuse of globally defined patternsets, avoid referencing any properties altogether.
Attributes
Type | Description |
---|---|
ElementNameAttribute | Indicates that class should be treated as a NAnt element. |
Constructors
Name | Summary |
---|---|
PatternSet |
Initializes a new instance of the NAnt.Core.Types.PatternSet class.
|
Properties
Name | Value | Summary |
---|---|---|
CanBeReferenced | bool |
Gets a value indicating whether a reference to the type can be
defined.
Inherited from DataTypeBase
|
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
|
Exclude | PatternCollection |
Defines a single pattern for files to exclude.
|
ExcludesFile | PatternCollection |
Loads multiple patterns of files to exclude from a given file, set
using the
NAnt.Core.Types.Pattern.PatternName parameter.
|
ID | string |
The ID used to be referenced later.
Inherited from DataTypeBase
|
Include | PatternCollection |
Defines a single pattern for files to include.
|
IncludesFile | PatternCollection |
Loads multiple patterns of files to include from a given file, set
using the
NAnt.Core.Types.Pattern.PatternName parameter.
|
Location | Location |
Gets or sets the location in the build file where the element is
defined.
Inherited from Element
|
Name | string |
Gets the name of the data type.
Inherited from DataTypeBase
|
NamespaceManager | XmlNamespaceManager |
Gets or sets the
System.Xml.XmlNamespaceManager .
Inherited from Element
|
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
|
RefID | string |
The ID to use as the reference.
Inherited from DataTypeBase
|
XmlNode | XmlNode |
Gets or sets the XML node of the element.
Inherited from Element
|
Methods
Name | Value | Summary |
---|---|---|
Append |
void |
Adds a nested set of patterns, or references other standalone
patternset.
|
CopyTo |
void |
Copies all instance data of the
NAnt.Core.DataTypeBase to a given
NAnt.Core.DataTypeBase .
Inherited from DataTypeBase
|
CopyTo |
void |
Copies all instance data of the
NAnt.Core.Element to a given
NAnt.Core.Element .
Inherited from Element
|
Get |
XmlNode |
Locates the XML node for the specified attribute in the project
configuration node.
Inherited from Element
|
Get |
XmlNode |
Inherited from Element
|
GetExcludePatterns |
string[] | |
GetIncludePatterns |
string[] | |
GetLocation |
Location |
Retrieves the location in the build file where the element is
defined.
Inherited from Element
|
Initialize |
void |
Derived classes should override to this method to provide extra
initialization and validation not covered by the base class.
Inherited from DataTypeBase
|
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
|
InitializeXml |
void |
Initializes all build attributes and child elements.
Inherited from Element
|
Log |
void |
Logs a message with the given priority.
Inherited from Element
|
Log |
void |
Logs a message with the given priority.
Inherited from Element
|
Reset |
void |
Should be overridden by derived classes. clones the referenced types
data into the current instance.
Inherited from DataTypeBase
|
See Also
- NAnt.Core.Types.FileSet