## org.apache.tools.ant.taskdefs.optional.dotnet
Class CSharp

    java.lang.Object
      |
      +--org.apache.tools.ant.ProjectComponent
            |
            +--org.apache.tools.ant.Task
                  |
                  +--org.apache.tools.ant.taskdefs.MatchingTask
                        |
                        +--org.apache.tools.ant.taskdefs.optional.dotnet.DotnetBaseMatchingTask
                              |
                              +--org.apache.tools.ant.taskdefs.optional.dotnet.DotnetCompile
                                    |
                                    +--org.apache.tools.ant.taskdefs.optional.dotnet.CSharp

All 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 `destFile`stops 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
Author:
  Steve Loughran

Nested Class Summary

Nested classes 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
`additionalModules, debug, definitionList, executable, extraOptions, mainClass, REFERENCE_OPTION, 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 java.lang.String` `createResourceParameter(DotnetResource resource)` from a resource, get the resource param string
`protected java.lang.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 java.lang.String` `getDocFileParameter()` get the argument or null for no argument needed
`protected java.lang.String` `getFileAlignParameter()` get the argument or null for no argument needed
`java.lang.String` `getFileExtension()` extension is '.cs'
`protected java.lang.String` `getFullPathsParameter()` Gets the fullPathsParameter attribute of the CSharp object
`boolean` `getIncremental()` query the incrementalflag
`protected java.lang.String` `getIncrementalParameter()` get the incremental build argument
`protected java.lang.String` `getNoConfigParameter()` Gets the noConfigParameter attribute of the CSharp object
`java.lang.String` `getReferenceDelimiter()` how does C# separate references? with a semi colon
`boolean` `getUnsafe()` query the Unsafe attribute
`protected java.lang.String` `getUnsafeParameter()` get the argument or null for no argument needed
`void` `setDefinitions(java.lang.String params)` Semicolon separated list of defined constants.
`void` `setDocFile(java.io.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(java.io.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

`addDefine, addReference, addReferenceFilesets, addResource, addResources, createNetCommand, execute, fillInSharedParameters, getAdditionalModulesParameter, getDebug, getDebugParameter, getDefinitionsDelimiter, getDestFileParameter, getExecutable, getExtraOptions, getExtraOptionsParameter, getFailOnError, getFilePattern, getIncludeDefaultReferences, getIncludeDefaultReferencesParameter, getMainClass, getMainClassParameter, getOptimize, getOptimizeParameter, 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

`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, XsetIgnore, XsetItems`

Methods inherited from class org.apache.tools.ant.Task
`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`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

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

### clear

    public void clear()

  full cleanup

  Overrides:
    `clear` in class `DotnetCompile`

### setDocFile

    public void setDocFile(java.io.File f)

  file for generated XML documentation

  Parameters:
    `f` - output file

### getDocFileParameter

    protected java.lang.String getDocFileParameter()

  get the argument or null for no argument needed

  Returns:
    The DocFile Parameter to CSC

### 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'

### getFileAlignParameter

    protected java.lang.String getFileAlignParameter()

  get the argument or null for no argument needed

  Returns:
    The OutputFile Parameter to CSC

### setFullPaths

    public void setFullPaths(boolean enabled)

  If true, print the full path of files on errors.

  Parameters:
    `enabled` - The new fullPaths value

### getFullPathsParameter

    protected java.lang.String getFullPathsParameter()

  Gets the fullPathsParameter attribute of the CSharp object

  Returns:
    The fullPathsParameter value or null if unset

### setIncremental

    public void setIncremental(boolean incremental)

  set the incremental compilation flag on or off.

  Parameters:
    `incremental` - on/off flag

### getIncremental

    public boolean getIncremental()

  query the incrementalflag

  Returns:
    true if incremental compilation is turned on

### getIncrementalParameter

    protected java.lang.String getIncrementalParameter()

  get the incremental build argument

  Returns:
    The Incremental Parameter to CSC

### setOutputFile

    public void setOutputFile(java.io.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

### getUnsafe

    public boolean getUnsafe()

  query the Unsafe attribute

  Returns:
    The Unsafe value

### getUnsafeParameter

    protected java.lang.String getUnsafeParameter()

  get the argument or null for no argument needed

  Returns:
    The Unsafe Parameter to CSC

### 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

### getNoConfigParameter

    protected java.lang.String getNoConfigParameter()

  Gets the noConfigParameter attribute of the CSharp object

  Returns:
    The noConfigParameter value

### setDefinitions

    public void setDefinitions(java.lang.String params)

  Semicolon separated list of defined constants.

  Parameters:
    `params` - The new definitions value

### getDefinitionsParameter

    protected java.lang.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 class `DotnetCompile`
  Returns:
    The Definitions Parameter to CSC

### addCompilerSpecificOptions

    public void addCompilerSpecificOptions(NetCommand command)

  add Commands unique to C#.

  Specified by:
    `addCompilerSpecificOptions` in class `DotnetCompile`
  Parameters:
    `command` - ongoing command

### getReferenceDelimiter

    public java.lang.String getReferenceDelimiter()

  how does C# separate references? with a semi colon

  Specified by:
    `getReferenceDelimiter` in class `DotnetCompile`
  Returns:
    The string delimiter for the reference string.

### getFileExtension

    public java.lang.String getFileExtension()

  extension is '.cs'

  Specified by:
    `getFileExtension` in class `DotnetCompile`
  Returns:

### createResourceParameter

    protected java.lang.String createResourceParameter(DotnetResource resource)

  from a resource, get the resource param string

  Specified by:
    `createResourceParameter` in class `DotnetCompile`
  Parameters:
    `resource` -
  Returns:
    a string containing the resource param, or a null string to conditionally exclude a resource.

Copyright © 2000-2003 Apache Software Foundation. All Rights Reserved.