CSharp (Apache Ant API)
Keywords: org.apache.tools.ant.taskdefs.optional.dotnet.CSharp class

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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

All Implemented Interfaces:
  SelectorContainer

public class CSharp
extends MatchingTask

Compiles C# source into executables or modules. The task will only work on win2K until other platforms support csc.exe or an equivalent. CSC.exe must be on the execute path too.

All parameters are optional: <csc/> should suffice to produce a debug build of all *.cs files. References to external files do require explicit enumeration, so are one of the first attributes to consider adding.

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 'outfile' seems prudent.

TODO

1. is incremental build still broken in beta-1?
2. is Win32Icon broken?
3. all the missing options

History

0.3 | Beta 1 edition | To avoid having to remember which assemblies to include, the task automatically refers to the main dotnet libraries in Beta1.
0.2 | Slightly different | Split command execution to a separate class;
0.1 | "I can't believe it's so rudimentary" | First pass; minimal builds only support;

Since:
  Ant 1.3
Version:
  0.5
Author:
  Steve Loughran steve_l@iseran.com

Field Summary
`protected boolean` | `debug` debug flag.
`protected static java.lang.String` | `DEFAULT_REFERENCE_LIST` Fix C# reference inclusion.
`protected java.lang.String` | `extraOptions` any extra command options?
`protected java.lang.String` | `mainClass` main class (or null for automatic choice)
`protected java.lang.String` | `targetType` type of target.
`protected boolean` | `unsafe` enable unsafe code flag.
`protected boolean` | `utf8output` utf out flag

Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask
`fileset, useDefaultExcludes`

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` | `Clear()` reset all contents.
`void` | `execute()` do the work by building the command line and then calling it
`protected java.lang.String` | `getAdditionalModulesParameter()` get the argument or null for no argument needed
`boolean` | `getDebug()` query the debug flag
`protected java.lang.String` | `getDebugParameter()` get the debug switch argument
`protected java.lang.String` | `getDefaultReferenceParameter()` get default reference list
`protected java.lang.String` | `getDefinitionsParameter()` get the argument or null for no argument needed
`protected java.lang.String` | `getDocFileParameter()` get the argument or null for no argument needed
`java.lang.String` | `getExtraOptions()` Gets the ExtraOptions attribute
`protected java.lang.String` | `getExtraOptionsParameter()` get any extra options or null for no argument needed
`boolean` | `getFailOnError()` query fail on error flag
`protected java.lang.String` | `getFileAlignParameter()` get the argument or null for no argument needed
`protected java.lang.String` | `getFullPathsParameter()` Gets the fullPathsParameter attribute of the CSharp object
`boolean` | `getIncludeDefaultReferences()` query automatic reference inclusion flag
`protected java.lang.String` | `getIncludeDefaultReferencesParameter()` get the include default references flag or null for no argument needed
`boolean` | `getIncremental()` query the incrementalflag
`protected java.lang.String` | `getIncrementalParameter()` get the incremental build argument
`java.lang.String` | `getMainClass()` Gets the MainClass attribute
`protected java.lang.String` | `getMainClassParameter()` get the /main argument or null for no argument needed
`protected java.lang.String` | `getNoConfigParameter()` Gets the noConfigParameter attribute of the CSharp object
`boolean` | `getOptimize()` query the optimise flag
`protected java.lang.String` | `getOptimizeParameter()` get the optimise flag or null for no argument needed
`protected java.lang.String` | `getOutputFileParameter()` get the argument or null for no argument needed
`protected java.lang.String` | `getReferenceFilesParameter()` turn the path list into a list of files and a /references argument
`protected java.lang.String` | `getReferencesParameter()` get the reference string or null for no argument needed
`java.lang.String` | `getTargetType()` Gets the TargetType attribute
`protected java.lang.String` | `getTargetTypeParameter()` get the argument or null for no argument needed
`boolean` | `getUnsafe()` query the Unsafe attribute
`protected java.lang.String` | `getUnsafeParameter()` get the argument or null for no argument needed
`protected java.lang.String` | `getUtf8OutputParameter()` Gets the utf8OutpuParameter attribute of the CSharp object
`int` | `getWarnLevel()` query warn level
`protected java.lang.String` | `getWarnLevelParameter()` get the warn level switch
`protected java.lang.String` | `getWin32IconParameter()` get the argument or null for no argument needed
`protected java.lang.String` | `getWin32ResParameter()` get the argument or null for no argument needed
`protected boolean` | `notEmpty(java.lang.String s)` test for a string containing something useful
`void` | `setAdditionalModules(java.lang.String params)` Semicolon separated list of modules to refer to.
`void` | `setDebug(boolean f)` set the debug flag on or off.
`void` | `setDefinitions(java.lang.String params)` Semicolon separated list of defined constants.
`void` | `setDestDir(java.io.File dirName)` Set the destination directory of files to be compiled.
`void` | `setDestFile(java.io.File file)` Set the name of exe/library to create.
`void` | `setDocFile(java.io.File f)` file for generated XML documentation
`void` | `setExtraOptions(java.lang.String extraOptions)` Any extra options which are not explicitly supported by this task.
`void` | `setFailOnError(boolean b)` If true, fail on compilation errors.
`void` | `setFileAlign(int fileAlign)` Set the file alignment.
`void` | `setFullPaths(boolean enabled)` If true, print the full path of files on errors.
`void` | `setIncludeDefaultReferences(boolean f)` If true, automatically includes the common assemblies in dotnet, and tells the compiler to link in mscore.dll.
`void` | `setIncremental(boolean f)` set the incremental compilation flag on or off.
`void` | `setMainClass(java.lang.String mainClass)` Sets the name of main class for executables.
`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` | `setOptimize(boolean f)` If true, enables optimization flag.
`void` | `setOutputFile(java.io.File params)` Set the output file
`void` | `setReferenceFiles(Path path)` Path of references to include.
`void` | `setReferences(java.lang.String s)` Semicolon separated list of DLLs to refer to.
`void` | `setSrcDir(java.io.File srcDirName)` Set the source directory of the files to be compiled.
`void` | `setTargetType(java.lang.String ttype)` Set the type of target.
`void` | `setUnsafe(boolean unsafe)` If true, enables the unsafe keyword.
`void` | `setUtf8Output(boolean enabled)` If true, require all compiler output to be in UTF8 format.
`void` | `setWarnLevel(int warnLevel)` Level of warning currently between 1 and 4 with 4 being the strictest.
`void` | `setWin32Icon(java.io.File fileName)` Set the filename of icon to include.
`void` | `setWin32Res(java.io.File fileName)` Sets the filename of a win32 resource (.RES) file to include.
`protected void` | `validate()` validation code

Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask
`addAnd, addContains, addCustom, addDate, addDepend, addDepth, addFilename, addMajority, addNone, addNot, addOr, addPresent, addSelector, addSize, 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, handleErrorFlush, handleErrorOutput, handleFlush, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName`

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

### DEFAULT_REFERENCE_LIST

    protected static final java.lang.String DEFAULT_REFERENCE_LIST

  Fix C# reference inclusion. C# is really dumb in how it handles inclusion. You have to list every 'assembly' -read DLL that is imported. So already you are making a platform assumption -shared libraries have a .dll;"+ extension and the poor developer has to know every library which is included why the compiler cant find classes on the path or in a directory, is a mystery. To reduce the need to be explicit, here is a long list of the core libraries used in Beta-1 of .NET ommitting the blatantly non portable (MS.win32.interop) and the .designer libraries. (ripping out Com was tempting) Casing is chosen to match that of the file system exactly so may work on a unix box too. there is no need to reference mscorlib.dll, cos it is always there

  See Also:
    Constant Field Values

### debug

    protected boolean debug

  debug flag. Controls generation of debug information.

### unsafe

    protected boolean unsafe

  enable unsafe code flag. Clearly set to false by default

### mainClass

    protected java.lang.String mainClass

  main class (or null for automatic choice)

### extraOptions

    protected java.lang.String extraOptions

  any extra command options?

### targetType

    protected java.lang.String targetType

  type of target. Should be one of exe|library|module|winexe|(null) default is exe; the actual value (if not null) is fed to the command line.
  See /target

### utf8output

    protected boolean utf8output

  utf out flag

Constructor Detail

### CSharp

    public CSharp()

  constructor inits everything and set up the search pattern

Method Detail

### setReferences

    public void setReferences(java.lang.String s)

  Semicolon separated list of DLLs to refer to.

  Parameters:
    `s` - The new References value

### getReferencesParameter

    protected java.lang.String getReferencesParameter()

  get the reference string or null for no argument needed

  Returns:
    The References Parameter to CSC

### setReferenceFiles

    public void setReferenceFiles(Path path)

  Path of references to include. Wildcards should work.

  Parameters:
    `path` - another path to append

### getReferenceFilesParameter

    protected java.lang.String getReferenceFilesParameter()

  turn the path list into a list of files and a /references argument

  Returns:
    null or a string of references.

### getDefaultReferenceParameter

    protected java.lang.String getDefaultReferenceParameter()

  get default reference list

  Returns:
    null or a string of references.

### setIncludeDefaultReferences

    public void setIncludeDefaultReferences(boolean f)

  If true, automatically includes the common assemblies in dotnet, and tells the compiler to link in mscore.dll. set the automatic reference inclusion flag on or off this flag controls the string of references and the /nostdlib option in CSC

  Parameters:
    `f` - on/off flag

### getIncludeDefaultReferences

    public boolean getIncludeDefaultReferences()

  query automatic reference inclusion flag

  Returns:
    true if flag is turned on

### getIncludeDefaultReferencesParameter

    protected java.lang.String getIncludeDefaultReferencesParameter()

  get the include default references flag or null for no argument needed

  Returns:
    The Parameter to CSC

### setOptimize

    public void setOptimize(boolean f)

  If true, enables optimization flag.

  Parameters:
    `f` - on/off flag

### getOptimize

    public boolean getOptimize()

  query the optimise flag

  Returns:
    true if optimise is turned on

### getOptimizeParameter

    protected java.lang.String getOptimizeParameter()

  get the optimise flag or null for no argument needed

  Returns:
    The Optimize Parameter to CSC

### setIncremental

    public void setIncremental(boolean f)

  set the incremental compilation flag on or off.

  Parameters:
    `f` - on/off flag

### getIncremental

    public boolean getIncremental()

  query the incrementalflag

  Returns:
    true iff incremental compilation is turned on

### getIncrementalParameter

    protected java.lang.String getIncrementalParameter()

  get the incremental build argument

  Returns:
    The Incremental Parameter to CSC

### setDebug

    public void setDebug(boolean f)

  set the debug flag on or off.

  Parameters:
    `f` - on/off flag

### getDebug

    public boolean getDebug()

  query the debug flag

  Returns:
    true if debug is turned on

### getDebugParameter

    protected java.lang.String getDebugParameter()

  get the debug switch argument

  Returns:
    The Debug Parameter to CSC

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

### setWarnLevel

    public void setWarnLevel(int warnLevel)

  Level of warning currently between 1 and 4 with 4 being the strictest.

  Parameters:
    `warnLevel` - warn level -see .net docs for valid range (probably 0-4)

### getWarnLevel

    public int getWarnLevel()

  query warn level

  Returns:
    current value

### getWarnLevelParameter

    protected java.lang.String getWarnLevelParameter()

  get the warn level switch

  Returns:
    The WarnLevel Parameter to CSC

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

### setMainClass

    public void setMainClass(java.lang.String mainClass)

  Sets the name of main class for executables.

  Parameters:
    `mainClass` - The new MainClass value

### getMainClass

    public java.lang.String getMainClass()

  Gets the MainClass attribute

  Returns:
    The MainClass value

### getMainClassParameter

    protected java.lang.String getMainClassParameter()

  get the /main argument or null for no argument needed

  Returns:
    The MainClass Parameter to CSC

### setExtraOptions

    public void setExtraOptions(java.lang.String extraOptions)

  Any extra options which are not explicitly supported by this task.

  Parameters:
    `extraOptions` - The new ExtraOptions value

### getExtraOptions

    public java.lang.String getExtraOptions()

  Gets the ExtraOptions attribute

  Returns:
    The ExtraOptions value

### getExtraOptionsParameter

    protected java.lang.String getExtraOptionsParameter()

  get any extra options or null for no argument needed

  Returns:
    The ExtraOptions Parameter to CSC

### setSrcDir

    public void setSrcDir(java.io.File srcDirName)

  Set the source directory of the files to be compiled.

  Parameters:
    `srcDirName` - The new SrcDir value

### setDestDir

    public void setDestDir(java.io.File dirName)

  Set the destination directory of files to be compiled.

  Parameters:
    `dirName` - The new DestDir value

### setTargetType

    public void setTargetType(java.lang.String ttype)
                       throws BuildException

  Set the type of target.

  Parameters:
    `ttype` - The new TargetType value
  Throws:
    `BuildException` - if target is not one of exe|library|module|winexe

### getTargetType

    public java.lang.String getTargetType()

  Gets the TargetType attribute

  Returns:
    The TargetType value

### getTargetTypeParameter

    protected java.lang.String getTargetTypeParameter()

  get the argument or null for no argument needed

  Returns:
    The TargetType Parameter to CSC

### setWin32Icon

    public void setWin32Icon(java.io.File fileName)

  Set the filename of icon to include.

  Parameters:
    `fileName` - path to the file. Can be relative, absolute, whatever.

### getWin32IconParameter

    protected java.lang.String getWin32IconParameter()

  get the argument or null for no argument needed

  Returns:
    The Win32Icon Parameter to CSC

### setWin32Res

    public void setWin32Res(java.io.File fileName)

  Sets the filename of a win32 resource (.RES) file to include. This is not a .NET resource, but what Windows is used to.

  Parameters:
    `fileName` - path to the file. Can be relative, absolute, whatever.

### getWin32ResParameter

    protected java.lang.String getWin32ResParameter()

  get the argument or null for no argument needed

  Returns:
    The Win32Res Parameter to CSC

### setUtf8Output

    public void setUtf8Output(boolean enabled)

  If true, require all compiler output to be in UTF8 format.

  Parameters:
    `enabled` - The new utf8Output value

### getUtf8OutputParameter

    protected java.lang.String getUtf8OutputParameter()

  Gets the utf8OutpuParameter attribute of the CSharp object

  Returns:
    The utf8OutpuParameter value

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

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

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

  get the argument or null for no argument needed

  Returns:
    The Definitions Parameter to CSC

### setAdditionalModules

    public void setAdditionalModules(java.lang.String params)

  Semicolon separated list of modules to refer to.

  Parameters:
    `params` - The new additionalModules value

### getAdditionalModulesParameter

    protected java.lang.String getAdditionalModulesParameter()

  get the argument or null for no argument needed

  Returns:
    The AdditionalModules Parameter to CSC

### setOutputFile

    public void setOutputFile(java.io.File params)

  Set the output file

  Parameters:
    `params` - The new outputFile value

### setDestFile

    public void setDestFile(java.io.File file)

  Set the name of exe/library to create.

  Parameters:
    `file` - The new outputFile value

### getOutputFileParameter

    protected java.lang.String getOutputFileParameter()

  get the argument or null for no argument needed

  Returns:
    The OutputFile Parameter to CSC

### setFailOnError

    public void setFailOnError(boolean b)

  If true, fail on compilation errors.

  Parameters:
    `b` - The new FailOnError value

### getFailOnError

    public boolean getFailOnError()

  query fail on error flag

  Returns:
    The FailFailOnError value

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

### Clear

    public void Clear()

  reset all contents.

### notEmpty

    protected boolean notEmpty(java.lang.String s)

  test for a string containing something useful

  Parameters:
    `s` - string in
  Returns:
    true if the argument is not null or empty

### validate

    protected void validate()
                     throws BuildException

  validation code

  Throws:
    `BuildException` - if validation failed

### execute

    public void execute()
                 throws BuildException

  do the work by building the command line and then calling it

  Overrides:
    `execute` in class `Task`
  Throws:
    `BuildException` - if validation or execution failed

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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