He,YuanHui —— 业精于勤荒于嬉,行成于思毁于随

如果你喜欢一个事,又有这样的才干,那就把整个人都投入进去,就要象一把刀直扎下去直到刀柄一样,不要问为什么,也不要管会碰到什么。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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"/> 

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> 
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> 
 
posted on 2010-05-30 13:19  He,YuanHui  阅读(517)  评论(0编辑  收藏  举报

Add to Google