通常在为 C# 编写构建脚本时,我只为每个要构建的项目/dll 包含 **/*.cs。但是,我现在遇到了一些 .cs 文件,这些文件不是项目的一部分,但存在于该目录中(它们存在于另一个库中以供参考)。.csproj 文件中没有链接,因此 VS 构建工作正常,但 nant 构建没有。
有谁知道是否有一种简单的方法可以将 .cs 条目从相关的 .csproj 文件中提取出来,并将其用作要构建的源文件列表,而不是使用通用通配符匹配。
提前致谢。
您不想将 msbuild仅用于 C# 构建位的任何特殊原因?这就是我为我的 Protocol Buffers 端口所做的,而且效果很好。它确实需要nant-contrib,但这并不是什么困难。
这样你就知道你只需要让一件事工作,并且知道它会以同样的方式构建。
您可以在此处查看我的 ProtoBuf 端口构建文件,以获得灵感。明显的缺点是对 Mono 的支持,但我相信 xBuild 正在改进......
nant支持使用任务自动构建 VS 解决方案,包括csproj
文件<solution>
。
最新支持的解决方案格式是 VS 2003。
Nantcontrib包含一个msbuild 任务- 您可以使用它来构建项目和解决方案。这是实践中的一个例子:http: //web.archive.org/web/20100913051600/http ://codebetter.com/blogs/jeffrey.palermo/archive/2006/08/12/148248.aspx
您可以通过 Exec 任务使用 MSBuild 构建项目,而不是直接调用编译器,例如msbuild project.csproj
.
使用 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>