如何替换已弃用的csc ant任务

时间:2010-03-12 17:27:24

标签: c# java ant nant

我有一个混合的Java / C#项目,并使用包含csc任务的ant脚本来编译dll。这有效,但我收到警告

  [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

如何更换csc任务?我当然可以使用project.build文件创建一个调用nant的exec任务,但这感觉完全错误。

编辑澄清一下:我主要是在Linux上使用这个并编写Nant脚本来编译项目的C#部分没问题。目前我通过

从Ant脚本中调用它
<target name="build-mono-stuff">
    <exec executable="nant">
        <arg value="build-stuff"/>
    </exec>
</target>

但我希望找到比调用exec更好的解决方案。

编辑2 所以我尝试从.NET AntLib中获取nant工作。这是我得到了多远:

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

首先运行:

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

然后我将Untntu nant包中的NAnt.exe放入PATH,然后我得到

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

有什么想法吗?

3 个答案:

答案 0 :(得分:1)

在我自己的NAnt文件中,我不使用<msbuild>任务 - 我直接执行msbuild.exe应用程序:

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

您应该能够在ant脚本中执行非常类似的操作。

注意:这确实假设您有msbuild可用,并且Visual Studio样式.sln文件可用,因此它不是csc的100%替代品,只是一个最适合的文件的情况。

答案 1 :(得分:1)

错误消息告诉您所有。

您应该避免使用诸如csc之类的低级命令,然后继续使用.NET Ant库中可用的NANT脚本来构建* .csproj项目。

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

就像使用另一个ANT库一样,该页面已经提供了基本示例。

答案 2 :(得分:0)

没有使用Ant的经验,这就是我在NAnt中的表现:

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

您可以将C#项目文件(甚至Visual Studio解决方案文件)直接传递给MSBuild。这应该比通过CSC这样做更方便。查找常见MSBuild属性列表here

相关问题