Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何替换不推荐的csc ant任务_C#_Java_Ant_Nant - Fatal编程技术网

C# 如何替换不推荐的csc ant任务

C# 如何替换不推荐的csc ant任务,c#,java,ant,nant,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任务?我当然

我有一个混合的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>
然后我把ubuntunant包中的NAnt.exe放到路径中,得到

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

有什么想法吗?

我没有使用Ant的经验,我会在NAnt这样做:

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


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

在我自己的
NAnt
文件中,我不使用
任务-我直接执行
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%替代品,只是适合大多数情况。

错误消息告诉您所有情况

您应该避免使用诸如csc之类的低级命令,并继续使用.NETAnt库中提供的命令来构建*.csproj项目或执行NANT脚本


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

而它所指向的.NET Antlib并不合适?我完全不确定这是如何工作的。如果您能给我一个调用这个.NETAntlib任务的示例(如果可能的话,可以从我的ant脚本中调用),我将非常高兴。
  <msbuild buildfile="foo.csproj">
    <property name="Configuration" value="Debug" />
    <!-- ... -->
  </msbuild>
<!-- 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>