将构建部署到具有构建号的文件夹非常简单。 CruiseControl.NET's NAnt task 自动将许多属性传递给您的 NAnt 脚本。 CCNetLabel 属性是您用来创建部署目录的属性。 CruiseControl.NET 文档中实际上有一个稍微过时的示例 NAnt 脚本就是这样做的。这是一个更好的版本:
<target name="publish">
<if test="${not property::exists('CCNetLabel')}">
<fail message="CCNetLabel property not set, so can't create labelled distribution files" />
</if>
<property name="publishDirectory" value="D:\Public\Project\Builds\${CCNetLabel}" />
<mkdir dir="${publishDirectory}" />
<copy todir="${publishDirectory}">
<fileset basedir="${buildDirectory}\bin">
<include name="*.dll" />
</fileset>
</copy>
</target>
就您的二进制文件进行版本控制而言,我发现以下方法比尝试更改您的 AssemblyInfo.cs 文件更简洁、更容易。基本上,我创建了一个 CommonAssemblyInfo.cs 文件,该文件位于任何项目之外,与您的解决方案文件位于同一目录中。此文件包含我正在构建的所有程序集共有的内容,例如公司名称、版权信息,当然还有版本。此文件在 Visual Studio 的每个项目中为 linked,因此每个项目都包含此信息(以及一个小得多的 AssemblyInfo.cs 文件,其中包含程序集特定信息,如程序集标题)。
通过 Visual Studio 或 NAnt 在本地构建项目时,将使用 CommonAssemblyInfo.cs 文件。但是,当项目由 CruiseControl.NET 构建时,我使用 NAnt 通过<asminfo> 任务替换该文件。 NAnt 脚本如下所示:
<target name="version">
<property name="commonAssemblyInfo" value="${buildDirectory}\CommonAssemblyInfo.cs" />
<!-- If build is initiated manually, copy standard CommonAssemblyInfo.cs file. -->
<if test="${not property::exists('CCNetLabel')}">
<copy file=".\src\CommonAssemblyInfo.cs" tofile="${commonAssemblyInfo}" />
</if>
<!-- If build is initiated by CC.NET, create a custom CommonAssemblyInfo.cs file. -->
<if test="${property::exists('CCNetLabel')}">
<asminfo output="${commonAssemblyInfo}" language="CSharp">
<imports>
<import namespace="System" />
<import namespace="System.Reflection" />
</imports>
<attributes>
<attribute type="AssemblyCompanyAttribute" value="My Company" />
<attribute type="AssemblyCopyrightAttribute" value="Copyright © 2008 My Company" />
<attribute type="AssemblyProductAttribute" value="My Product" />
<attribute type="AssemblyVersionAttribute" value="1.0.0.${CCNetLabel}" />
<attribute type="AssemblyInformationalVersionAttribute" value="1.0.0.${CCNetLabel}" />
</attributes>
<references>
<include name="System.dll" />
</references>
</asminfo>
</if>
</target>
<target name="build-my-project" depends="version">
<csc target="library" output="${buildDirectory}\bin\MyProject.dll">
<sources>
<include name=".\src\MyProject\*.cs"/>
<include name=".\src\MyProject\**\*.cs"/>
<include name="${commonAssemblyInfo}"/>
</sources>
</csc>
</target>
注意 AssemblyVersionAttribute 和 AssemblyInformationalVersionAttribute 值在 version 目标中的设置位置。 CCNetLabel 属性被插入到版本号中。为了获得额外的好处,您可以使用像前面提到的 SvnRevisionLabeller 这样的 CruiseControl.NET 插件。使用它,我们得到带有“2.1.8239.0”标签的构建,其中“8239”对应于我们正在构建的Subversion修订号。我们将这个内部版本号直接转储到我们的 AssemblyVersionAttribute 和 AssemblyInformationalVersionAttributes 中,并且我们的内部版本号和程序集上的版本号都可以轻松追溯到我们版本中的特定修订控制系统。