2010-03-12 26 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庫和頁面提供了基本的例子了。

相關問題