2010-06-21 261 views
2

通常,在为C#构建脚本时,我只为每个要构建的项目/ dll添加**/* .cs。然而,我现在有一种情况,我有一些.cs文件,这些文件不是该项目的一部分,而是位于该目录中(它们出于其他库的参考目的)。在.csproj文件中没有链接,所以VS构建工作正常,但是nant构建没有。C#使用.csproj文件构建

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

在此先感谢。

回答

4

任何特定的原因,你不想使用msbuild 只是为了C#构建位?这就是我为Protocol Buffers端口所做的,并且它工作正常。它确实需要nant-contrib,但这并不困难。

这样你就知道你只需要做一件事情,知道它会以同样的方式构建。

你可以看看我的ProtoBuf端口构建文件here,以获取灵感。明显的缺点是支持单声道,但我相信xBuild正在改进...

+0

这正是我们如何做到的。通过像Lee这样的'exec'任务调用MSBuild也可以,但是使用nantcotrib的'msbuild'任务更加舒适。 – 2010-06-21 17:20:20

+0

谢谢,msbuild肯定是要走的路。我的构建文件大约是现在的1/4。 – 2010-06-22 08:31:49

+0

我试图用xbuild(.sln)构建你的ProtoBuf端口,生成很好:) – radical 2010-06-22 12:49:37

3

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

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

+4

“现在只支持Microsoft Visual Studio .NET 2002和2003解决方案和项目。”这些日子听起来不是非常有用。 – 2010-06-21 16:58:27

2

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

1

使用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> 
相关问题