NAnt SDK Documentation - v0.92

PatternSet Class

A set of patterns, mostly used to include or exclude certain files.

For a list of all members of this type, see PatternSet Members.

System.Object
   NAnt.Core.Element
      NAnt.Core.DataTypeBase
         NAnt.Core.Types.PatternSet

[Visual Basic]
<ElementName(Name:="patternset")>
Public Class PatternSet
    Inherits DataTypeBase
[C#]
[ElementName(Name="patternset")]
public class PatternSet : DataTypeBase

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

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 IncludesFile and 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 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.

Example

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:

Requirements

Namespace: NAnt.Core.Types

Assembly: NAnt.Core (in NAnt.Core.dll)

See Also

PatternSet Members | NAnt.Core.Types Namespace | FileSet