NAnt和构建版本 [英] NAnt and build version

查看:97
本文介绍了NAnt和构建版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Nant自动化ClickOnce构建.因此,在构建应用程序之后,我需要知道它的版本(出于创建文件夹的目的).我还需要构建自动增量.

I use Nant for automating ClickOnce build. So after building the application I need to know what is its version (for purpose of folder creation). Also I need build autoincrementing.

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

推荐答案

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

As far as I understood, you would like to do version detection/management with minimal effort.

为什么不使用AssemblyInfo自动增量功能.将[assembly: AssemblyVersion("1.0.*")]放入AssemblyInfo.cs将使每次构建的内部版本号递增.在

Why don't you use AssemblyInfo auto-increment capabilities. Putting [assembly: AssemblyVersion("1.0.*")] into your AssemblyInfo.cs will increment the build number with every build. Find more information in this answer.

编译后,您可以通过

After compilation you can detect the assembly version via NAnt function assemblyname::get-version:

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

更新: 如果您不能使用Assembly info自动增加功能,则可以让NAnt使用

Update: If you can't use Assembly info auto-increment capabilities, you might let NAnt create AssemblyInfo.cs with every build using NAntContrib's <version>-task.

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

这篇关于NAnt和构建版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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