2010-03-12 247 views
3

我有一个混合的Java/C#项目,并使用包含csc任务的ant脚本来编译dll。这工作,但我得到一个警告如何替换已弃用的csc ant任务

[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任务?我肯定可以创建一个exec任务,调用nant与project.build文件,但是这种感觉完全错误。

编辑澄清:我主要在Linux上使用这种编写Nant脚本来编译项目的C#部分是没有问题的。目前我从蚂蚁脚本中调用它

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

然后我把NAnt.exe从Ubuntu楠包到路径,我得到

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

任何想法?

+0

它指向你的.NET Antlib不适合? – 2010-03-12 18:44:52

+0

我不确定,这是如何工作的。我会很高兴,如果你能给我一个调用这个.NET Antlib任务的例子(如果可能的话从我的ant脚本中)。 – GrGr 2010-03-12 22:00:05

回答

0

经与蚂蚁的经验,这是我会怎么做,在楠:

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

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

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文件可用,所以它不是100%替换为csc,只适用于大多数情况。

1

错误消息告诉你所有。

您应该避免使用低级命令(如csc),然后继续构建* .csproj项目或执行.NET Ant文件夹中可用的NANT脚本。

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

这就像使用其他ANT库和页面提供了基本的例子了。

相关问题