.NET tasks

Introduction

These tasks are deprecated and will be removed in a future release of Ant. They are now part of the .NET Antlib.

Ant support for .NET goes back to before .NET was released, and continues to be expanded based on user demand. Users writing nothing but a .NET application, may want to look at the .NET-based NAnt project, that supports both the Microsoft and the Ximian managed Mono project's implementation of the .NET framework.

Over time, the .NET tasks in Ant have tended to evolve to meet a few limited needs. Firstly, developers working with complex deployment problems may want to use ant to use the fairly advanced deployment tasks Ant ships with. Secondly, anyone who has a cross-platform project can use these tasks to cover the .NET side of the problem. Here, cross-platform can mean more than just Java and .NET: the C++ tasks in the ant-contrib project on sourceforge can be used with Ant to do native C++ and .NET cross development if that is your need. Finally, Ant support for .NET lets one automate .NET development under an automated build process, such as AntHill or Cruise Control.

What this means is that the Ant tasks for .NET support do not get as much rigorous use as the Java tools, and are evolving more slowly -that includes the time for support calls to change. But as a consequence, developers working on .NET support have more freedom to play around with the code. It also means that the fairly unusual set of tasks supported by ant enable a few interesting operations that can not be performed any other way:

  1. Integrating with a Java based SOAP Service -generating C# code from the server's WSDL and running it against the server.
  2. Building and deploying a C#-based Web Service, then using the Apache Axis tasks to create JUnit tests to call the endpoints.
  3. Patching .NET type libraries to work with more complex IDL than the basic <importtypelib> wrapper around tlbimport supports. Hence the disassembler and the reassembler.
Needless to say, possible does not mean easy. Chapter 15 of Java Development with Ant covers the first of these, using the Ant1.5 version of the tasks. Going the other way -generating Java client code and JUnit testcases is covered in The Wondrous curse of Interop. The final trick, IDL and Typelib abuse, is not documented as we do not want to encourage such an ugly practise. It, can, however, be done if absolutely necessary.

Task List

Task Description
csc Compiles C# code
vbc Compiles VB.NET code
jsharpc Compiles J# files
ildasm Disassembles .NET executables and libraries
ilasm Assembles .il files
wsdltodotnet Generates .NET code (C# or VB) from a WSDL file
importtypelib Imports a COM type library into .NET

Common .NET Datatypes

There are some datatypes that are common to the core compiler classes: csc, vbc and jsharpc

Resource

This is a resource that is included in the build. Ant uses this for dependency checking -if resources included this way have changed, the executable or library will be rebuilt.

Attribute Description Required
File the resource to include Yes
name the name of the resource. Optional unless the resource is marked as public or private No
embed flag to control whether the resource is embedded in the assembly, or just linked to it No -default is true
public VB only: flag to control if a resource should be public or private. Set to true for public, false for private and leave undefined for for neither. No

Examples
<resource file="app.ico" name="icon"/>
<resource file="splash.jpg"/>
<resource name="splash" file="splash.jpg" public="false"/>

Define

This is a definition; in .NET these can either be defined or undefined, unlike C++ #defines, which can be either undefined or arbitrary text. The Ant compilation tasks can unconditionally add definitions, or conditionally set a compile-time definition if an ant property is defined or not.

Dependency Logic: the tasks are not (yet) clever enough to remember what the last definitions were and trigger a rebuild when they change. Clean build the code when the defines are likely to be different.

Attribute Description Required
name the name of the definition Yes
if name of a ant property to test for; the definition is only set if this property is defined. No
unless name of a ant property to test for; the definition is only set if this property is undefined. No

Examples
<define name="unsafe"/>
<define name="debug" if="build.debug"/>
<define name="dotnet" unless="build.mono"/>

Change Log

Ant1.6

This revision goes along with NET 1.1, though there is no reason why it should not work on other versions.

  1. vbc task
  2. jsharpc task
  3. mono support
  4. ilasm
  5. tlbimport
  6. Reference filesets in the compiler tasks
  7. definitions in the compiler tasks
  8. multiple source filesets in the compiler tasks. If these are used, the implicit fileset is disabled
The compile tasks: vbc, jsharpc, and csc, all contain lots of common code in a shared base class: if you can use one you should be able to use another.

Ant 1.5

This revision goes along with NET 1.0 (SP1)
  1. CSC: added filealign
  2. CSC: added reference to office.dll
  3. CSC: dependency checking! only if destFile is set!
  4. WsdlToDotnet written

Version 0.5

This revision goes along with NET 1.0 (SP1)
  1. CSC: added filealign
  2. CSC: added reference to office.dll
  3. CSC: dependency checking! only if destFile is set!
  4. WsdlToDotnet written

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

Internal changes 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.