使用SVN修订版在CCNET中标记构建

使用SVN修订版在CCNET中标记构建

本文介绍了使用SVN修订版在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现在具有程序集版本标签程序,它生成与.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)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<Target Name="BeforeBuild">
  <AssemblyInfo Condition="'$(CCNetLabel)' != ''" CodeLanguage="CS" OutputFile="Properties\AssemblyInfo.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修订版在CCNET中标记构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:11