【问题标题】:How to replace the deprecated csc ant task如何替换已弃用的 csc ant 任务
【发布时间】:2010-03-12 17:27:24
【问题描述】:

我有一个混合 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 更好的解决方案。

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

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

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

有什么想法吗?

【问题讨论】:

  • 而你指向的.NET Antlib 不适合?
  • 我不确定,这是如何工作的。如果你能给我一个调用这个 .NET Antlib 任务的例子(如果可能的话,来自我的 ant 脚本),我会很高兴。

标签: c# java ant nant


【解决方案1】:

在我自己的NAnt 文件中,我不使用&lt;msbuild&gt; 任务——我直接执行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,它只是适合大多数情况的一种。

【讨论】:

    【解决方案2】:

    错误信息告诉你一切。

    您应该避免使用 csc 等低级命令,并继续使用 .NET Ant 库中提供的 NANT 脚本构建您的 *.csproj 项目。

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

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

    【讨论】:

      【解决方案3】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2020-02-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多