NAnt and build version

柔情痞子 提交于 2019-12-13 03:44:55

问题


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.

For building I use msbuild.exe /t:publish


回答1:


For this you can use your source code repository revision number/hash as that is often used when using subversion or git repositories.

You can also make use of a buildserver like cruisecontrol (ccnet) this will do this build version incrementing for you.




回答2:


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

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

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>


来源:https://stackoverflow.com/questions/6860985/nant-and-build-version

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!