NAnt和构建版本

时间:2011-07-28 14:50:26

标签: nant

我使用Nant自动执行ClickOnce构建。因此,在构建应用程序之后,我需要知道它的版本是什么(用于创建文件夹)。我还需要构建自动增量。

对于构建我使用msbuild.exe /t:publish

2 个答案:

答案 0 :(得分:0)

为此,您可以使用源代码存储库修订号/散列,这在使用subversion或git存储库时经常使用。

您还可以使用像cruisecontrol(ccnet)这样的构建服务器,这将为您增加此构建版本。

答案 1 :(得分:0)

据我了解,您希望以最小的努力进行版本检测/管理。

为什么不使用AssemblyInfo自动增量功能。将[assembly: AssemblyVersion("1.0.*")]放入AssemblyInfo.cs会增加每次构建的内部版本号。在this answer中找到更多信息。

编译后,您可以通过NAnt function assemblyname::get-version检测装配版本:

assemblyname::get-version(assemblyname::get-assembly-name('MyAssembly.dll'))

<强>更新 如果您不能使用程序集信息自动增量功能,则可以让NAnt使用NAntContrib's <version>-task为每个构建创建AssemblyInfo.cs。

<loadtasks assembly="C:\PathToNAntContibTasks\NAnt.Contrib.Tasks.dll" />
<target name="assemblyinfo" description="generates AssemblyInfo.cs">
  <property
    name="working.dir"
    value="C:\src\foo" />
  <property
    name="build.number.path"
    value="${path::combine(working.dir, 'build.number')}" />
  <echo
    file="${build.number.path}"
    message="0.0.0.0"
    unless="${file::exists(build.number.path)}" />
  <version
    buildtype="Increment"
    path="${build.number.path}"/>
  <foreach
    item="File"
    property="assemblyinfo.path">
    <in>
      <items>
        <include name="${path::combine(working.dir, '**\AssemblyInfo.cs')}" />
      </items>
    </in>
    <do>
      <asminfo output="${assemblyinfo.path}" language="CSharp">
        <imports>
          <import namespace="System.Reflection" />
        </imports>
        <attributes>
          <attribute type="AssemblyVersionAttribute" value="${buildnumber.version}" />
        </attributes>
      </asminfo>
    </do>
  </foreach>
</target>