org.apache.tools.ant.taskdefs.optional.dotnet

Class CSharp

public class CSharp extends DotnetCompile

Compiles C# source into executables or modules. csc.exe on Windows or mcs on other platforms must be on the execute path, unless another executable or the full path to that executable is specified in the executable parameter

All parameters are optional: <csc/> should suffice to produce a debug build of all *.cs files. However, naming an destFilestops the csc compiler from choosing an output name from random, and allows the dependency checker to determine if the file is out of date.

The task is a directory based task, so attributes like includes="*.cs" and excludes="broken.cs" can be used to control the files pulled in. By default, all *.cs files from the project folder down are included in the command. When this happens the output file -if not specified- is taken as the first file in the list, which may be somewhat hard to control. Specifying the output file with destFile seems prudent.

For more complex source trees, nested src elemements can be supplied. When such an element is present, the implicit fileset is ignored. This makes sense, when you think about it :)

For historical reasons the pattern **/*.cs is preset as includes list and you can not override it with an explicit includes attribute. Use nested <src> elements instead of the basedir attribute if you need more control.

References to external files can be made through the references attribute, or (since Ant1.6), via nested <reference> filesets. With the latter, the timestamps of the references are also used in the dependency checking algorithm.

Example

<csc
 	optimize="true"
 	debug="false"
 	docFile="documentation.xml"
 	warnLevel="4"
 	unsafe="false"
 	targetType="exe"
 	incremental="false"
 	mainClass = "MainApp"
 	destFile="NetApp.exe"
 	>
 	     <src dir="src" includes="*.cs" />
       <reference file="${testCSC.dll}" />
       <define name="RELEASE" />
       <define name="DEBUG" if="debug.property"/>
       <define name="def3" unless="def3.property"/>
    </csc>
 

Since: Ant 1.3

UNKNOWN: name="csc" category="dotnet"

Field Summary
protected booleanunsafe
enable unsafe code flag.
Constructor Summary
CSharp()
constructor inits everything and set up the search pattern
Method Summary
voidaddCompilerSpecificOptions(NetCommand command)
add Commands unique to C#.
voidclear()
full cleanup
protected StringcreateResourceParameter(DotnetResource resource)
from a resource, get the resource param string
protected StringgetDefinitionsParameter()
override the superclasses version of this method (which we call) with a check for a definitions attribute, the contents of which are appended to the list.
protected StringgetDocFileParameter()
get the argument or null for no argument needed
protected StringgetFileAlignParameter()
get the argument or null for no argument needed
StringgetFileExtension()
This method indicates the filename extension for C# files.
protected StringgetFullPathsParameter()
Gets the fullPathsParameter attribute of the CSharp object
booleangetIncremental()
query the incrementalflag
protected StringgetIncrementalParameter()
get the incremental build argument
protected StringgetNoConfigParameter()
Gets the noConfigParameter attribute of the CSharp object
StringgetReferenceDelimiter()
Returns the delimiter which C# uses to separate references, i.e., a semi colon.
booleangetUnsafe()
query the Unsafe attribute
protected StringgetUnsafeParameter()
get the argument or null for no argument needed
voidsetDefinitions(String params)
Semicolon separated list of defined constants.
voidsetDocFile(File f)
file for generated XML documentation
voidsetFileAlign(int fileAlign)
Set the file alignment.
voidsetFullPaths(boolean enabled)
If true, print the full path of files on errors.
voidsetIncremental(boolean incremental)
set the incremental compilation flag on or off.
voidsetNoConfig(boolean enabled)
A flag that tells the compiler not to read in the compiler settings files 'csc.rsp' in its bin directory and then the local directory
voidsetOutputFile(File params)
The output file.
voidsetUnsafe(boolean unsafe)
If true, enables the unsafe keyword.

Field Detail

unsafe

protected boolean unsafe
enable unsafe code flag. Clearly set to false by default

Constructor Detail

CSharp

public CSharp()
constructor inits everything and set up the search pattern

Method Detail

addCompilerSpecificOptions

public void addCompilerSpecificOptions(NetCommand command)
add Commands unique to C#.

Parameters: command ongoing command

clear

public void clear()
full cleanup

createResourceParameter

protected String createResourceParameter(DotnetResource resource)
from a resource, get the resource param string

Parameters: resource

Returns: a string containing the resource param, or a null string to conditionally exclude a resource.

getDefinitionsParameter

protected String getDefinitionsParameter()
override the superclasses version of this method (which we call) with a check for a definitions attribute, the contents of which are appended to the list.

Returns: The Definitions Parameter to CSC

getDocFileParameter

protected String getDocFileParameter()
get the argument or null for no argument needed

Returns: The DocFile Parameter to CSC

getFileAlignParameter

protected String getFileAlignParameter()
get the argument or null for no argument needed

Returns: The OutputFile Parameter to CSC

getFileExtension

public String getFileExtension()
This method indicates the filename extension for C# files.

Returns: the file extension for C#, i.e., "cs" (without the dot).

getFullPathsParameter

protected String getFullPathsParameter()
Gets the fullPathsParameter attribute of the CSharp object

Returns: The fullPathsParameter value or null if unset

getIncremental

public boolean getIncremental()
query the incrementalflag

Returns: true if incremental compilation is turned on

getIncrementalParameter

protected String getIncrementalParameter()
get the incremental build argument

Returns: The Incremental Parameter to CSC

getNoConfigParameter

protected String getNoConfigParameter()
Gets the noConfigParameter attribute of the CSharp object

Returns: The noConfigParameter value

getReferenceDelimiter

public String getReferenceDelimiter()
Returns the delimiter which C# uses to separate references, i.e., a semi colon.

getUnsafe

public boolean getUnsafe()
query the Unsafe attribute

Returns: The Unsafe value

getUnsafeParameter

protected String getUnsafeParameter()
get the argument or null for no argument needed

Returns: The Unsafe Parameter to CSC

setDefinitions

public void setDefinitions(String params)
Semicolon separated list of defined constants.

Parameters: params The new definitions value

setDocFile

public void setDocFile(File f)
file for generated XML documentation

Parameters: f output file

setFileAlign

public void setFileAlign(int fileAlign)
Set the file alignment. Valid values are 0,512, 1024, 2048, 4096, 8192, and 16384, 0 means 'leave to the compiler'

setFullPaths

public void setFullPaths(boolean enabled)
If true, print the full path of files on errors.

Parameters: enabled The new fullPaths value

setIncremental

public void setIncremental(boolean incremental)
set the incremental compilation flag on or off.

Parameters: incremental on/off flag

setNoConfig

public void setNoConfig(boolean enabled)
A flag that tells the compiler not to read in the compiler settings files 'csc.rsp' in its bin directory and then the local directory

Parameters: enabled The new noConfig value

setOutputFile

public void setOutputFile(File params)
The output file. This is identical to the destFile attribute.

Parameters: params The new outputFile value

setUnsafe

public void setUnsafe(boolean unsafe)
If true, enables the unsafe keyword.

Parameters: unsafe The new Unsafe value

Copyright B) 2000-2007 Apache Software Foundation. All Rights Reserved.