代码之家  ›  专栏  ›  技术社区  ›  GrGr

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

  •  3
  • GrGr  · 技术社区  · 16 年前

    我有一个混合的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任务?我当然可以创建一个exec任务,通过一个项目调用nant。构建文件,但感觉完全不对。

    编辑

    <target name="build-mono-stuff">
        <exec executable="nant">
            <arg value="build-stuff"/>
        </exec>
    </target>
    

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

    编辑2 所以我试着从他那里弄到南特。NET AntLib开始工作。这就是我取得的成绩:

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

    然后我把南特放进去。从UbuntuNant包进入路径,我得到

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

    有什么想法吗?

    3 回复  |  直到 16 年前
        1
  •  1
  •   Bevan    16 年前

    在我自己 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 ,只是一个适合大多数情况的。

        2
  •  1
  •   Lex Li    16 年前

    错误消息会告诉你一切。

    您应该避免使用诸如csc之类的低级命令,并继续构建您的*。csproj项目或执行NANT脚本,这些脚本在中可用。NET蚂蚁库。

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

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

        3
  •  0
  •   The Chairman    16 年前

    由于没有蚂蚁的经验,我会在南特这样做:

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

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

    推荐文章