使用CruiseControl.net构建部署
我已经看到了一些关于如何进行构建部署的示例,但是我有一些独特的事情要做:使用CruiseControl.net构建部署,.net,cruisecontrol.net,nant,.net,Cruisecontrol.net,Nant,我已经看到了一些关于如何进行构建部署的示例,但是我有一些独特的事情要做: 将生成部署到具有生成编号的文件夹(例如Project\Builds\8423) 更改.NET AssmblyInfo.cs中的版本号以匹配内部版本号 以前有人使用NAnt+CruiseControl.NET在.NET项目中这样做过吗?我没有使用NAnt,但我们已经用C编写了一个自定义应用程序,它读取程序集并增加版本号 我们从ccnet配置中的exec块调用它 创建文件夹和复制文件对于添加到该应用程序来说是微不足道的 我们的
以前有人使用NAnt+CruiseControl.NET在.NET项目中这样做过吗?我没有使用NAnt,但我们已经用C编写了一个自定义应用程序,它读取程序集并增加版本号 我们从ccnet配置中的exec块调用它 创建文件夹和复制文件对于添加到该应用程序来说是微不足道的 我们的想法是,我们整天都在使用C语言,因此修复/修改用C语言编写的构建程序会更快,如果我们不得不在这之上学习nant脚本的内部功能的话
显然,如果您一直使用nant,就没有理由不构建一个定制的nant插件来完成这项工作我同意BumperBox,一个单独的组件来完成增加构建数量的繁重任务,这也是我几年前采取的路线。它的优点是能够应对其他外部因素。例如,如果配置文件中存在特定条件,您可能希望增加版本号或内部版本号。请查看此项。尽管它使用了MSBuild,但差别很小 CC.NET将distrib目录和版本传递给脚本,该脚本是脚本的简单包装器。版本号用于文件夹和包命名,也用于程序集版本 版本号来自CC.NET的
最后。您可以使用传递到NAnt脚本中的CCNetLabel属性来设置它部署到的位置 至于AssemblyInfo,对于MSBuild,中有一个工作正常的任务。不知道NAnt等价物是什么,尽管可以在更改它的NAnt脚本之前运行MSBuild脚本 配置很简单:
<AssemblyInfo CodeLanguage="C#"
OutputFile="%(YourProjects.RootDir)%(Directory)Properties\AssemblyInfo.cs"
AssemblyVersion="$(CCNetLabel)"
/>
您需要添加所需的任何其他属性,这将覆盖AssemblyInfo文件。将生成部署到具有生成编号的文件夹非常简单。自动将许多属性传递给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中的每个项目中,因此每个项目都包含此信息(以及一个小得多的AssemblyInfo.cs文件,其中包含特定于程序集的信息,如程序集标题)
当通过Visual Studio或NAnt在本地构建项目时,将使用CommonAssemblyInfo.cs文件。但是,当CruiseControl.NET构建项目时,我使用NAnt通过任务替换该文件。以下是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>
. 使用它,我们得到了标签为“2.1.8239.0”的构建,其中“8239”对应于我们构建的Subversion版本号。我们将此版本号直接转储到AssemblyVersionAttribute和AssemblyInformationalVersionAttribute中,我们的版本号和程序集上的版本号都可以很容易地追溯到版本控制系统中的特定版本。我对巡航控制和nAnt也很陌生,但我发现非常有用
不完美也不漂亮,但它确实完成了任务
还有一个(Scott似乎也参与其中)。您使用的是什么源代码管理系统?它有版本号吗?