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

Class CSharp

Implemented Interfaces:
SelectorContainer

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 :)

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

Nested Class Summary

Nested classes/interfaces inherited from class org.apache.tools.ant.taskdefs.optional.dotnet.DotnetCompile

DotnetCompile.TargetTypes

Field Summary

protected boolean
unsafe
enable unsafe code flag.

Fields inherited from class org.apache.tools.ant.taskdefs.optional.dotnet.DotnetCompile

REFERENCE_OPTION, additionalModules, debug, definitionList, executable, extraOptions, mainClass, referenceFilesets, resources, targetType, utf8output

Fields inherited from class org.apache.tools.ant.taskdefs.optional.dotnet.DotnetBaseMatchingTask

filesets, outputFile, srcDir

Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask

fileset

Fields inherited from class org.apache.tools.ant.Task

description, location, target, taskName, taskType, wrapper

Fields inherited from class org.apache.tools.ant.ProjectComponent

project

Constructor Summary

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

Method Summary

void
addCompilerSpecificOptions(NetCommand command)
add Commands unique to C#.
void
clear()
full cleanup
protected String
createResourceParameter(DotnetResource resource)
from a resource, get the resource param string
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.
protected String
getDocFileParameter()
get the argument or null for no argument needed
protected String
getFileAlignParameter()
get the argument or null for no argument needed
String
getFileExtension()
This method indicates the filename extension for C# files.
protected String
getFullPathsParameter()
Gets the fullPathsParameter attribute of the CSharp object
boolean
getIncremental()
query the incrementalflag
protected String
getIncrementalParameter()
get the incremental build argument
protected String
getNoConfigParameter()
Gets the noConfigParameter attribute of the CSharp object
String
getReferenceDelimiter()
Returns the delimiter which C# uses to separate references, i.e., a semi colon.
boolean
getUnsafe()
query the Unsafe attribute
protected String
getUnsafeParameter()
get the argument or null for no argument needed
void
setDefinitions(String params)
Semicolon separated list of defined constants.
void
setDocFile(File f)
file for generated XML documentation
void
setFileAlign(int fileAlign)
Set the file alignment.
void
setFullPaths(boolean enabled)
If true, print the full path of files on errors.
void
setIncremental(boolean incremental)
set the incremental compilation flag on or off.
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
void
setOutputFile(File params)
The output file.
void
setUnsafe(boolean unsafe)
If true, enables the unsafe keyword.

Methods inherited from class org.apache.tools.ant.taskdefs.optional.dotnet.DotnetCompile

addCompilerSpecificOptions, addDefine, addReference, addReferenceFilesets, addResource, addResources, clear, createNetCommand, createResourceParameter, execute, fillInSharedParameters, getAdditionalModulesParameter, getDebug, getDebugParameter, getDefinitionsDelimiter, getDefinitionsParameter, getDestFileParameter, getExecutable, getExtraOptions, getExtraOptionsParameter, getFailOnError, getFileExtension, getFilePattern, getIncludeDefaultReferences, getIncludeDefaultReferencesParameter, getMainClass, getMainClassParameter, getOptimize, getOptimizeParameter, getReferenceDelimiter, getReferenceFilesParameter, getReferencesParameter, getTargetType, getTargetTypeParameter, getUtf8OutputParameter, getWarnLevel, getWarnLevelParameter, getWin32IconParameter, getWin32Res, getWin32ResParameter, isFileManagedBinary, isUseResponseFile, notEmpty, setAdditionalModules, setDebug, setDestDir, setExecutable, setExtraOptions, setFailOnError, setIncludeDefaultReferences, setMainClass, setOptimize, setReferenceFiles, setReferences, setTargetType, setTargetType, setUseResponseFile, setUtf8Output, setWarnLevel, setWin32Icon, setWin32Res, validate

Methods inherited from class org.apache.tools.ant.taskdefs.optional.dotnet.DotnetBaseMatchingTask

addFilesAndExecute, addFilesToCommand, addSrc, buildFileList, getDestFile, getOutputFileTimestamp, getSrcDir, setDestFile, setSrcDir

Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask

XsetIgnore, XsetItems, add, addAnd, addContains, addContainsRegexp, addCustom, addDate, addDepend, addDepth, addDifferent, addFilename, addMajority, addModified, addNone, addNot, addOr, addPresent, addSelector, addSize, addType, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject

Methods inherited from class org.apache.tools.ant.Task

execute, getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType

Methods inherited from class org.apache.tools.ant.ProjectComponent

getProject, log, log, setProject

Field Details

unsafe

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

Constructor Details

CSharp

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

Method Details

addCompilerSpecificOptions

public void addCompilerSpecificOptions(NetCommand command)
add Commands unique to C#.
Overrides:
addCompilerSpecificOptions in interface DotnetCompile

Parameters:
command - ongoing command


clear

public void clear()
full cleanup
Overrides:
clear in interface DotnetCompile


createResourceParameter

protected String createResourceParameter(DotnetResource resource)
from a resource, get the resource param string
Overrides:
createResourceParameter in interface DotnetCompile

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.
Overrides:
getDefinitionsParameter in interface DotnetCompile

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.
Overrides:
getFileExtension in interface DotnetCompile

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.
Overrides:
getReferenceDelimiter in interface DotnetCompile


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-2005 Apache Software Foundation. All Rights Reserved.