FileDocCategorySizeDatePackage
CSharp.javaAPI DocApache Ant 1.7011076Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs.optional.dotnet

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>
ant.task
name="csc" category="dotnet"
since
Ant 1.3

Fields Summary
String
definitions
defines list: RELEASE;WIN32;NO_SANITY_CHECKS;;SOMETHING_ELSE'
private File
docFile
output XML documentation flag
private int
fileAlign
file alignment; 0 means let the compiler decide
private boolean
fullpaths
use full paths to things
private boolean
incremental
incremental build flag
protected boolean
unsafe
enable unsafe code flag. Clearly set to false by default
private boolean
noconfig
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
Constructors Summary
public CSharp()
constructor inits everything and set up the search pattern

    // CheckStyle:VisibilityModifier ON


                   

      
        clear();
    
Methods Summary
public voidaddCompilerSpecificOptions(NetCommand command)
add Commands unique to C#.

param
command ongoing command

        command.addArgument(getIncludeDefaultReferencesParameter());
        command.addArgument(getWarnLevelParameter());
        command.addArgument(getDocFileParameter());
        command.addArgument(getFullPathsParameter());
        command.addArgument(getFileAlignParameter());
        command.addArgument(getIncrementalParameter());
        command.addArgument(getNoConfigParameter());
        command.addArgument(getUnsafeParameter());
    
public voidclear()
full cleanup

        super.clear();
        docFile = null;
        fileAlign = 0;
        fullpaths = true;
        incremental = false;
        unsafe = false;
        noconfig = false;
        definitions = null;
        setExecutable(isWindows ? "csc" : "mcs");
    
protected voidcreateResourceParameter(NetCommand command, DotnetResource resource)
Build a C# style parameter.

param
command the command.
param
resource the resource.

        resource.getParameters(getProject(), command, true);
    
protected java.lang.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.

return
The Definitions Parameter to CSC

        String predecessors = super.getDefinitionsParameter();
        if (notEmpty(definitions)) {
            if (predecessors == null) {
                predecessors = "/define:";
            }
            return  predecessors + definitions;
        } else {
            return predecessors;
        }
    
protected java.lang.StringgetDocFileParameter()
get the argument or null for no argument needed

return
The DocFile Parameter to CSC

        if (docFile != null) {
            return "/doc:" + docFile.toString();
        } else {
            return null;
        }
    
protected java.lang.StringgetFileAlignParameter()
get the argument or null for no argument needed

return
The OutputFile Parameter to CSC

        if (fileAlign != 0 && !"mcs".equals(getExecutable())) {
            return "/filealign:" + fileAlign;
        } else {
            return null;
        }
    
public java.lang.StringgetFileExtension()
This method indicates the filename extension for C# files.

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

        return "cs";
    
protected java.lang.StringgetFullPathsParameter()
Gets the fullPathsParameter attribute of the CSharp object

return
The fullPathsParameter value or null if unset

        return fullpaths ? "/fullpaths" : null;
    
public booleangetIncremental()
query the incrementalflag

return
true if incremental compilation is turned on

        return incremental;
    
protected java.lang.StringgetIncrementalParameter()
get the incremental build argument

return
The Incremental Parameter to CSC

        return "/incremental" + (incremental ? "+" : "-");
    
protected java.lang.StringgetNoConfigParameter()
Gets the noConfigParameter attribute of the CSharp object

return
The noConfigParameter value

        return noconfig ? "/noconfig" : null;
    
public java.lang.StringgetReferenceDelimiter()
Returns the delimiter which C# uses to separate references, i.e., a semi colon.

return
the delimiter.

        return ";";
    
public booleangetUnsafe()
query the Unsafe attribute

return
The Unsafe value

        return this.unsafe;
    
protected java.lang.StringgetUnsafeParameter()
get the argument or null for no argument needed

return
The Unsafe Parameter to CSC

        return unsafe ? "/unsafe" : null;
    
public voidsetDefinitions(java.lang.String params)
Semicolon separated list of defined constants.

param
params The new definitions value

        definitions = params;
    
public voidsetDocFile(java.io.File f)
file for generated XML documentation

param
f output file

        docFile = f;
    
public voidsetFileAlign(int fileAlign)
Set the file alignment. Valid values are 0,512, 1024, 2048, 4096, 8192, and 16384, 0 means 'leave to the compiler'

param
fileAlign the value to use.

        this.fileAlign = fileAlign;
    
public voidsetFullPaths(boolean enabled)
If true, print the full path of files on errors.

param
enabled The new fullPaths value

        fullpaths = enabled;
    
public voidsetIncremental(boolean incremental)
set the incremental compilation flag on or off.

param
incremental on/off flag

        this.incremental = incremental;
    
public 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

param
enabled The new noConfig value

        noconfig = enabled;
    
public voidsetOutputFile(java.io.File params)
The output file. This is identical to the destFile attribute.

param
params The new outputFile value

        setDestFile(params);
    
public voidsetUnsafe(boolean unsafe)
If true, enables the unsafe keyword.

param
unsafe The new Unsafe value

        this.unsafe = unsafe;