tags:

views:

396

answers:

3

I have a mixed Java / C# project and use an ant script that contains a csc task to compile the dll. This works, but I get a warning

  [csc] This task is deprecated and will be removed in a future version
  [csc] of Ant.  It is now part of the .NET Antlib:
  [csc] http://ant.apache.org/antlibs/dotnet/index.html

How can I replace the csc task? I can surely create an exec task calling nant with a project.build file, but that feels completely wrong.

EDIT To clarify: I am mainly using this on Linux and writing the Nant script to compile the C# part of the project is no problem. Currently I call it from the Ant script by

<target name="build-mono-stuff">
    <exec executable="nant">
        <arg value="build-stuff"/>
    </exec>
</target>

but I hoped to find a better solution than invoking an exec.

EDIT 2 So I tried get the nant from .NET AntLib to work. This is how far I got:

<taskdef name="mono-compile" classname="org.apache.ant.dotnet.build.NAntTask">
    <classpath location="lib/ant-dotnet-1.0.jar" />
</taskdef>
<target name="build-mono-stuff">
    <mono-compile buildfile="mono.build"></mono-compile>
</target>

First run:

[mono-compile] Cannot open assembly 'NAnt.exe': No such file or directory.

Then I put NAnt.exe from the Ubuntu nant package into the PATH and I get

[mono-compile] The "nant" section in the NAnt configuration file (/bin/NAnt.exe.config) is not available.

Any ideas?

A: 

Having no experience with Ant, this is how I would do it in NAnt:

  <msbuild buildfile="foo.csproj">
    <property name="Configuration" value="Debug" />
    <!-- ... -->
  </msbuild>

You may pass C# project files (or even Visual Studio solution files) directly to MSBuild. That should be much more convenient than doing it through CSC. Find a list of common MSBuild properties here.

The Chairman
+1  A: 

In my own NAnt files, I don't use the <msbuild> task - I execute the msbuild.exe application directly:

<!-- Ensure MSBuild is available -->
<property name="msbuild.dir"
          value="C:\WINDOWS\Microsoft.NET\Framework\v3.5"/>
<property name="msbuild.exe"
          value="${path::combine(msbuild.dir, 'MSBuild.exe')}"/>  
<fail message="MSBuild not fould in ${msbuild.dir}"
      unless="${file::exists( msbuild.exe )}"/>

<!-- Compile everything -->
<exec program="${msbuild.exe}">
  <arg file="NAntGraph2.sln"/>
  <arg value="/t:rebuild"/>
  <arg value="/verbosity:quiet"/>
</exec>

You should be able to do something pretty similar in your ant script.

Note: this does assume that you have msbuild available, and a Visual Studio style .sln file available, so it's not a 100% replacement for csc, just one that suits most situations.

Bevan
A: 

The error message tells you all.

You should avoid using low level commands such as csc, and move on to build your *.csproj project with or execute NANT script with which are available in .NET Ant Library.

http://ant.apache.org/antlibs/dotnet/index.html

It's just like using another ANT library and the page provides basic examples already.

Lex Li