# .NET classes for Ant

## Vision

Make ant the definitive build tool for .NET projects, just as it is becoming for java projects

## Detail

The emergent policy in big java projects is 'IDE for code and debug'; Ant for builds, test and deployment. While IDEs are great for an individual development task, Ant not only rebuilds everything insanely fast, it has great support for modern deployment tasks -ftp upload, EJB servers, SQL commands, all can be done from a relatively simple XML declaration of what you want done. Also in a large project (especially open source) there is no means of dictating which IDE to use. Ant gives IDE independence, cross platform portability and ease of extensibility.

Projects using .net should be able to use the same tool. This will avoid everyone being dependent on Visual Studio.net (if they have it) supplemented with makefiles and batch files. Anyone doing mixed java/dotnet development will be particulary grateful, as they can have a unified build process.

If at sometime in the future bits of .net do appear on different platforms then ant based build files will migrate -once the ant tasks have been migrated and any hard codings of DOS-descendant file system conventions removed from the build.xml files.

## Key .net Tasks

1. csc - csharp compiler - *.csc -> output
2. ilasm - IL assembler - *.il ->.exe or .dll
3. ResX - ResXToResources.exe .resx -> .resources
4. al - assembly linker (.dll) ->
5. Signcode - .exe + keys -> .exe
6. Resgen - .properties -> .resources
7. Type Library Exporter (TlbExp.exe) .dll -> .tlb
8. TlbImp.exe Type Library Importer
9. RegAsm.exe Assembly Registration Tool .dll -> .reg | registration

## Ant Wrapper for net tasks

Rarely used .net command line tools can be invoked manually. The key tasks to address are the common steps in a build process and those which benefit from the file pattern matching function.

The esoteric tasks can then supported on demand by those who need them. The initial .net tasks should provide a foundation for that demand creation to be simple.

## Plan

1. code up C sharp task and distribute for feedback & identify possible aid
2. Use for a real end to end development task
3. Add the next task I need (whatever that is)
4. Refactor to produce a base class for .net tasks
5. Leave it other people write all the other tasks

## Risks

- The .net SDK is unstable; the next builds will change the commands, arguments and behaviours. Probability: 100%. Impact: 2 days.
- Portable tasks turn out to be harder than envisaged (=reworking if/when non Win32 .net build tools appear)

## Using Ant in .net projects

To use the net tasks one needs

- A Windows box (or any other platform which supports the .net build tools)
- JavaVM - Java1.1 or later; Java1.3 recommended.
- Ant downloaded and the environment and path variables set up so that typing 'ant' invokes ant via a batch file.
- An XML parser for ant. The usual distributions include an appropriate version crimson.jar and jaxp.jar.
- the .net tasks archive (dotnettasks.jar) included in the ant\lib directory
- The .net sdk installed with the binaries on the path. (Test: type CSC)
- A build.xml file to describe the build process

## Change Log

#### Version 0.4

This is the beta-2 revision of the tasks.

1. ILASM: pulled the owner attribute, added keyfile for giving binaries a strong name (MD5 hash of the checksum)
2. CSC: added win32res , noConfig, utf8output, fullpaths
3. CSC:

#### Version 0.3

The changes here reflect Beta-1 of the dotnet SDK and experience of use in more complex projects. This build does not work with the older SDK, primarily because the automatic reference feature references libraries only found in the new SDK version.

External changes

- Recursive inclusion of .cs and .il files
- Documentation enhanced, includes examples and details of all parameters
- The csc task automatically includes the common dotnet assemblies, so there is no need to remember to refer to 'System.dll', 'System.Web.Services', etc. This feature can be disabled by setting the 'includeDefaultReferences' flag to false.
- References can also be referred to using the ReferenceFiles parameter, which is an ant path specification. The old 'references' string is still retained.
- An 'extraoptions' attribute enables the build file to include any CSC options which are not explicitly supported in the CSC task.

Internal changes

- Some minor refactoring (move common code a method)
- Application of Jedits JavaStyle task resulted in a major reshaping of the codebase and the insertion of a blank line every second line. Significant effort was required to revert some (but not all) changes.
- Removed throws clause from methods which can't throw exceptions

The test harness has been expanded to include unicode source file (the build works but the rest of the system has 'issues' with high unicode package and method names)

#### Version 0.2

First public edition, added to the ant cvs tree. Tested on the PDC build of the dotnet SDK only, and still immature. The command execution code was refactored out into a 'NetCommand' class for re-use. The Ilasm task was added at this time.

#### Version 0.1

Initial proof of concept; very rudimentary support for CSC only.

## Task: CSC

This task compiles CSharp source into executables or modules. This task compiles CSharp 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.

Attribute | Description | Example Values
additionalModules | Semicolon separated list of modules to refer to
defaultexcludes | indicates whether default excludes should be used or not | "true"(default) or "false"
definitions | defined constants | "RELEASE;BETA1"
debug | include debug information | "true"(default) or "false"
docFile | name of file for documentation | "doc.xml"
excludes | comma separated list of patterns of files that must be excluded. No files (except default excludes) are excluded when omitted.
excludesfile | the name of a file. Each line of this file is taken to be an exclude pattern
extraOptions | Any extra options which aren't explicitly supported by the CSharp task | "/warnaserror+ /baseaddress:0x12840000"
failOnError | Should a failed compile halt the build? | "true"(default) or "false"
fullpaths | print the full path of files on on errors
includes | comma separated list of patterns of files that must be included. All files are included when omitted.
includeDefaultReferences | Flag which when true automatically includes the common assemblies in dotnet beta1, and tells the compiler to link in mscore.dll | "true"(default) or "false"
includesfile | the name of a file. Each line of this file is taken to be an include pattern
incremental | Incremental build flag. Avoid till it works | "true" or "false"(default)
mainClass | name of main class for executables | "com.example.project.entrypoint"
noConfig | a flag which tells the compiler not to read in the compiler settings files 'csc.rsp' in its bin directory and then the local directory | "true" or "false"(default)
optimize | optimisation flag | "true" or "false"(default)
outputFile | filename of output | "example.exe"
references | Semicolon separated list of dlls to refer to | "mylib.dll;nunit.dll"
referenceFiles | Ant Path descriptioon of references to include. Wildcards should work. |
srcDir | source directory (default = project directory) | "."
targetType | Type of target | "exe", "module", "winexe" or "library"
unsafe | enable the unsafe keyword | "true" or "false"(default)
utf8output | require all compiler output to be in utf-8 format | "true" or "false"(default)
warnLevel | level of warning currently between 1 and 4 with 4 being the strictest. | "1"-"4"
win32Icon | filename of icon to include | "res/myicon.ico"
win32res | filename of a win32 resource (.RES)file to include This is not a .NET resource, but it what windows is used to. | "res/myapp.res"

Example

    <csc
            optimize="true"
            debug="false"
            docFile="documentation.xml"
            warnLevel="4"
            unsafe="false"
            targetType="exe"
            incremental="false"
            definitions="RELEASE"
            excludes="src/unicode_class.cs"
            mainClass = "MainApp"
            outputFile="NetApp.exe"
            />

## Task: ilasm

Task to assemble .net 'Intermediate Language' files. The task will only work on windows until other platforms support csc.exe or an equivalent. ilasm.exe must be on the execute path too.

All parameters are optional: <il/> should suffice to produce a debug build of all *.il files. The option set is roughly compatible with the CSharp class; even though the command line options are only vaguely equivalent. [The low level commands take things like /OUT=file, csc wants /out:file ... /verbose is used some places; /quiet here in ildasm... etc.] It would be nice if someone made all the command line tools consistent (and not as brittle as the java cmdline tools)

The task is a directory based task, so attributes like includes="*.il" and excludes="broken.il" can be used to control the files pulled in. Each file is built on its own, producing an appropriately named output file unless manually specified with outfile

Attribute | Description | Example
defaultexcludes | indicates whether default excludes should be used or not ("yes"/"no"). Default excludes are used when omitted.
debug | include debug information | true (default)
excludes | comma separated list of patterns of files that must be excluded. No files (except default excludes) are excluded when omitted.
excludesfile | the name of a file. Each line of this file is taken to be an exclude pattern
extraOptions | Any extra options which aren't explicitly supported by the ilasm task, primarily because they arent really documented: use ilasm /? to see them |
failOnError | Should a failed compile halt the build? | "true"(default)
fullpaths | Should error text provide the full path to files | "true"(default)
includes | comma separated list of patterns of files that must be included. All files are included when omitted.
includesfile | the name of a file. Each line of this file is taken to be an include pattern
keyfile | the name of a file containing a private key, with which the assembly output is checksumed and then MD5 signed to have a strong name
listing | Produce a listing (off by default). Listings go to the current output stream | "on", "off" (default)
outputFile | filename of output | "example.exe"
resourceFile | name of resource file to include | "resources.res"
srcDir | source directory (default = project directory) |
targetType | Type of target. library means DLL is output. | "exe"(default), "library"
verbose | output progress messages | "on", "off" (default)

Example

    <ilasm
            outputFile="app.exe"
            verbose="on"
            listing="on"
            owner="secret"
            />

Copyright © 2000 Apache Software Foundation. All rights Reserved.