开发者

nant <version> task

开发者 https://www.devze.com 2023-02-17 09:13 出处:网络
How can I use nanttasks to increment build versions? To be more specific how can I link this up with version numbers in assembly开发者_高级运维info.cs?You\'ll want to consider some sort of system for

How can I use nant tasks to increment build versions? To be more specific how can I link this up with version numbers in assembly开发者_高级运维info.cs?


You'll want to consider some sort of system for managing your version increments. One common way to do it is through continuous integration such as CruiseControl.NET. If you go this route, you can use a build target like this:

<target name="set.version" description="generates the version number">
    <echo message="Setting the build version to ${CCNetLabel}..." />
    <attrib file="AssemblyInfo.cs" readonly="false" />
    <asminfo output="AssemblyInfo.cs" language="CSharp">
        <imports>
            <import namespace="System" />
            <import namespace="System.Reflection" />
        </imports>
        <attributes>
            <attribute type="AssemblyVersionAttribute" value="${CCNetLabel}" />
            <attribute type="AssemblyFileVersionAttribute" value="${CCNetLabel}" />
        </attributes>
    </asminfo>
    <attrib file="AssemblyInfo.cs" readonly="true" />
</target>

Where CCNetLabel is a dynamic property that is set from CruiseControl when it executes nant.


NAnt's <asminfo> task helps you with generating AssemblyInfo.cs.


We use TeamCity to supply NAnt with a version number. The version number is then injected into the AssemblyInfo like this.:

<asminfo output="${solutionDir}/CommonAssemblyInfo.cs" language="CSharp">
      <imports>
        <import namespace="System" />
        <import namespace="System.Reflection" />
      </imports>
      <attributes>
        <attribute type="AssemblyVersionAttribute" value="${version}" />
      </attributes>
    </asminfo>

This creates a CommonAssemblyInfo.cs file with the specified version, which needs to be linked to all the projects in your solution.


I am using multiple referenced projects ( Windows Forms , Class Library and BatchConsole)

Best example will be to copy the "section of Assemblyinfo" from nAnt Build file( you can download it from Github )

The Trick is you can use a commonAssemblyinfo file which your nAnt Targets will refer to it.

Below the target from nAnt file

<target name="create-common-assemblyinfo" if="${create.assemblyinfo}">
    <!-- ensure src/CommonAssemblyInfo.cs is writable if it already exists -->
    <attrib file="src/CommonAssemblyInfo.cs" readonly="false" if="${file::exists('src/CommonAssemblyInfo.cs')}" />
    <!-- generate the source file holding the common assembly-level attributes -->
    <asminfo output="src/CommonAssemblyInfo.cs" language="CSharp">
        <imports>
            <import namespace="System" />
            <import namespace="System.Reflection" />
            <import namespace="System.Runtime.InteropServices" />
        </imports>
        <attributes>
            <attribute type="ComVisibleAttribute" value="false" />
            <attribute type="CLSCompliantAttribute" value="true" />
            <attribute type="AssemblyTitleAttribute" value="NAnt" />
            <attribute type="AssemblyDescriptionAttribute" value="A .NET Build Tool" />
            <attribute type="AssemblyConfigurationAttribute" value="${project.release.type}" />
            <attribute type="AssemblyCompanyAttribute" value="http://nant.sourceforge.net" />
            <attribute type="AssemblyProductAttribute" value="NAnt" />
            <attribute type="AssemblyCopyrightAttribute" value="Copyright (C) 2001-${datetime::get-year(datetime::now())} Gerry Shaw" />
            <attribute type="AssemblyTrademarkAttribute" value="" />
            <attribute type="AssemblyCultureAttribute" value="" />
            <attribute type="AssemblyVersionAttribute" value="${project.version}.${build.number}.0" />
            <attribute type="AssemblyInformationalVersionAttribute" value="${project.version}" />
        </attributes>
    </asminfo>
</target>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号