【问题标题】:C# nant build using .csproj files使用 .csproj 文件的 C# nant 构建
【发布时间】:2010-06-21 16:45:37
【问题描述】:

通常在为 C# 编写构建脚本时,我只为每个要构建的项目/dll 包含 **/*.cs。但是,我现在有一些 .cs 文件,这些文件不是项目的一部分,但存在于该目录中(它们存在于另一个库中以供参考)。 .csproj 文件中没有链接,因此 VS 构建工作正常,但 nant 构建没有。

有谁知道是否有一种简单的方法可以将 .cs 条目从相关的 .csproj 文件中提取出来,并将其用作要构建的源文件列表,而不是使用通用通配符匹配。

提前致谢。

【问题讨论】:

    标签: c# build nant csproj


    【解决方案1】:

    您不想使用 msbuild 仅用于 C# 构建位的任何特殊原因?这就是我为我的 Protocol Buffers 端口所做的,而且效果很好。 确实需要nant-contrib,但这并不是什么难事。

    这样你就知道你只需要让一件事工作,并且知道它会以同样的方式构建。

    您可以查看我的 ProtoBuf 端口构建文件 here,以获得灵感。明显的缺点是对 Mono 的支持,但我相信 xBuild 正在改进......

    【讨论】:

    • 这正是我们的做法。像 Lee 建议的那样通过 exec 任务调用 MSBuild 也可以,但使用 nantcotrib 的 msbuild 任务会更舒服。
    • 谢谢,msbuild 绝对是正确的选择。我的构建文件现在大约是 1/4 大小。
    • 我尝试使用 xbuild(.sln)构建您的 ProtoBuf 端口,构建良好:)
    • @Ankit:太好了。那我必须试一试。端口的 Mono 构建脚本目前有点原始:)
    【解决方案2】:

    nant 有 support 用于使用 <solution> 任务自动构建 VS 解决方案,包括 csproj 文件。

    最新支持的解决方案格式是 VS 2003。

    【讨论】:

    • “目前,仅支持 Microsoft Visual Studio .NET 2002 和 2003 解决方案和项目。”这些天听起来不是很有用。
    【解决方案3】:

    Nantcontrib 包含一个msbuild task - 您可以使用它来构建项目和解决方案。下面是一个在实践中的例子:http://web.archive.org/web/20100913051600/http://codebetter.com/blogs/jeffrey.palermo/archive/2006/08/12/148248.aspx

    【讨论】:

      【解决方案4】:

      您可以通过 Exec 任务使用 MSBuild 构建项目,而不是直接调用编译器,例如msbuild project.csproj.

      【讨论】:

        【解决方案5】:

        使用 MSBuild 是个好主意。但是,如果有任何孤立文件(.cs 文件不在 .csproj 中),aspnet_compile.exe 有时会失败。为了解决这个问题,我编写了以下内容来删除所有未包含在 .csproj 中的 *.cs 文件。到目前为止一切顺利,感谢任何反馈。

        <project>
         <foreach item="File" property="csprojFile">
         <in>
          <items>
           <include name="source/**/*.csproj" />
          </items>
         </in>
         <do>
          <property name="currentFolder" value="${directory::get-current-directory()}" />
          <property name="csprojParentFolder" value="${directory::get-parent-directory(csprojFile)}" />
        
          <foreach item="File" property="csFile">
           <in>
            <items>
             <include name="${csprojParentFolder}/**/*.cs"/>
            </items>
           </in>
           <do>
        
            <property name="csFileRelativePath" value="${string::replace(csFile, csprojParentFolder + '\', '')}" />
            <loadfile property="projFile" file="${csprojFile}" />
            <if test="${not string::contains(projFile, csFileRelativePath)}">
             <echo message="${csprojFile}:  | Missing: ${csFileRelativePath}" />
             <!-- <delete file="${csprojParentFolder + '\' + csFileRelativePath}" /> -->
            </if>
           </do>
          </foreach>
        
         </do>
         </foreach>
        </project>
        

        【讨论】:

          猜你喜欢
          • 2011-12-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-05-15
          相关资源
          最近更新 更多