使用CruiseControl.net构建部署

use*_*222 6 .net cruisecontrol.net nant

我已经看到了一些关于如何进行构建部署的示例,但是我有一些我想做的独特之处:

  1. 将构建部署到具有内部版本号的文件夹(例如,Project\Builds\8423)
  2. 更改.NET AssmblyInfo.cs中的版本号以匹配内部版本号

有没有人在使用NAnt + CruiseControl.net的.NET项目之前做过这个?

小智 11

使用内部版本号将构建部署到文件夹非常简单. CruiseControl.NET的NAnt任务会自动将许多属性传递给您的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>
Run Code Online (Sandbox Code Playgroud)

至于二进制文件的版本控制,我发现以下方法比尝试更改AssemblyInfo.cs文件更简洁.基本上我创建一个CommonAssemblyInfo.cs文件,该文件位于任何项目之外,与解决方案文件位于同一目录中.此文件包含我正在构建的所有程序集共有的内容,例如公司名称,版权信息,当然还有版本.此文件在Visual Studio中的每个项目中链接,因此每个项目都包含此信息(以及一个小得多的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>
Run Code Online (Sandbox Code Playgroud)

请注意在版本目标中设置AssemblyVersionAttributeAssemblyInformationalVersionAttribute值的位置.该CCNetLabel财产被插入到版本号.为了获得额外的好处,您可以使用CruiseControl.NET插件,如前面提到的SvnRevisionLabeller.使用它,我们得到像"2.1.8239.0"这样的标签,其中"8239"对应于我们正在构建的Subversion版本号.我们将此构建号直接转储到AssemblyVersionAttributeAssemblyInformationalVersionAttributes中,我们的版本号和我们程序集上的版本号都可以很容易地追溯到我们的版本控制系统中的特定版本.


小智 1

我还没有使用 nant 完成此操作,但我们已经用 C# 编写了一个自定义应用程序,该应用程序读取程序集并递增版本号。

我们从 ccnet 配置中的 exec 块调用它。

创建文件夹并复制文件添加到该应用程序中很简单

我们的想法是我们整天都在使用 C#,因此修复/更改用 C# 编写的构建程序会更快,然后如果我们必须在此基础上学习 nant 脚本的内部结构

显然,如果你一直使用 nant,就没有理由不构建一个自定义的 nant 插件来完成这项工作