使用SVN Revision在CCNET中标记构建 [英] Use SVN Revision to label build in CCNET

查看:16
本文介绍了使用SVN Revision在CCNET中标记构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个以 SVN 作为源代码管理的示例项目中使用 CCNET.CCNET 配置为在每次签入时创建一个构建版本.CCNET 使用 MSBuild 构建源代码.

I am using CCNET on a sample project with SVN as my source control. CCNET is configured to create a build on every check in. CCNET uses MSBuild to build the source code.

我想在编译时使用最新的修订号生成AssemblyInfo.cs.如何从 subversion 中检索最新版本并使用 CCNET 中的值?

I would like to use the latest revision number to generate AssemblyInfo.cs while compiling. How can I retrieve the latest revision from subversion and use the value in CCNET?

我没有使用 NAnt - 只有 MSBuild.

I'm not using NAnt - only MSBuild.

推荐答案

CruiseControl.Net 1.4.4 现在有一个 Assembly Version Labeler,生成与 .Net 程序集属性兼容的版本号.

CruiseControl.Net 1.4.4 has now an Assembly Version Labeller, which generates version numbers compatible with .Net assembly properties.

在我的项目中,我将其配置为:

In my project I have it configured as:

<labeller type="assemblyVersionLabeller" incrementOnFailure="true" major="1" minor="2"/>

(警告:assemblyVersionLabeller 在实际提交触发的构建发生之前不会开始生成基于 svn 修订的标签.)

(Caveat: assemblyVersionLabeller won't start generating svn revision based labels until an actual commit-triggered build occurs.)

然后使用 MSBuildCommunityTasks.AssemblyInfo 从我的 MSBuild 项目中使用它:

and then consume this from my MSBuild projects with MSBuildCommunityTasks.AssemblyInfo :

<Import Project="$(MSBuildExtensionsPath)MSBuildCommunityTasksMSBuild.Community.Tasks.Targets"/>
<Target Name="BeforeBuild">
  <AssemblyInfo Condition="'$(CCNetLabel)' != ''" CodeLanguage="CS" OutputFile="PropertiesAssemblyInfo.cs" 
  AssemblyTitle="MyTitle" AssemblyCompany="MyCompany" AssemblyProduct="MyProduct"
  AssemblyCopyright="Copyright ©  2009" ComVisible="false" Guid="some-random-guid"
  AssemblyVersion="$(CCNetLabel)" AssemblyFileVersion="$(CCNetLabel)"/>
</Target>

为了完整起见,使用 NAnt 而不是 MSBuild 的项目同样容易:

For sake of completness, it's just as easy for projects using NAnt instead of MSBuild:

<target name="setversion" description="Sets the version number to CruiseControl.Net label.">
    <script language="C#">
        <references>
            <include name="System.dll" />
        </references>
        <imports>
            <import namespace="System.Text.RegularExpressions" />
        </imports>
        <code><![CDATA[
             [TaskName("setversion-task")]
             public class SetVersionTask : Task
             {
              protected override void ExecuteTask()
              {
               StreamReader reader = new StreamReader(Project.Properties["filename"]);
               string contents = reader.ReadToEnd();
               reader.Close();
               string replacement = "[assembly: AssemblyVersion("" + Project.Properties["CCNetLabel"] + "")]";
               string newText = Regex.Replace(contents, @"[assembly: AssemblyVersion("".*"")]", replacement);
               StreamWriter writer = new StreamWriter(Project.Properties["filename"], false);
               writer.Write(newText);
               writer.Close();
              }
             }
             ]]>
        </code>
    </script>
    <foreach item="File" property="filename">
        <in>
            <items basedir="..">
                <include name="**AssemblyInfo.cs"></include>
            </items>
        </in>
        <do>
            <setversion-task />
        </do>
    </foreach>
</target>

这篇关于使用SVN Revision在CCNET中标记构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆