0

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

spraff
  • 32,570
  • 22
  • 121
  • 229
weqew q
  • 271
  • 3
  • 10

2 Answers2

0

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.

Ramon Smits
  • 2,482
  • 1
  • 18
  • 20
  • I use nant for publishing. So if I change something witout check in into source safe, publish it, then I see a mistake, fix it and publish again. (note that I nevere check in it in source safe, so version number in source control didn't change but it changed in application) – weqew q Jul 29 '11 at 14:05
0

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>
Community
  • 1
  • 1
The Chairman
  • 7,087
  • 2
  • 36
  • 44
  • Because when you use msbuild /t:publish it doesn't increment version even you mark the assembly by this flag. Thank you for NAnt function that is what I need. – weqew q Jul 30 '11 at 14:44