User Guide

See also: Matt Griffith's original user guide. The following started out as an adaptation of that.

Overview

UpdateVersion searches its input for a .NET AssemblyVersion attribute and calculates a new version number using one of several algorithms. Input can be either a file or the standard input stream. Output options are the same -- either a file or the standard output stream. UpdateVersion is typically used to update AssemblyInfo.* files as part of a build script, batch file, or make file. New versions consist of an updated build and/or revision number. The build number can either be incremented by one or calculated based on the project start date. Revision numbers are either incremented or based on the number of seconds since midnight.

Note: Build number format is <major>.<minor>.<build>.<revision>

Command Line Options

Short Form Long Form Valid Values Description
-v --version Assembly | File The version number to update. The default is Assembly which is backward compatible with previous versions. Use –v Assembly to update the AssemblyVersion attribute. Use –v File to update the AssemblyFileVersion attribute.
-s --startdate Any date string which DateTime can parse for the current culture (i.e. 2002-11-23) The date the project started. The startdate option is required if the MonthDay build type is specified; otherwise, the startdate option is ignored.
-b --build Fixed | MonthDay | Increment | BuildDay | <date format> The algorithm used to calculate the build number. The default is Fixed meaning the build number will remain the same if you do not specify one of the other build algorithms. MonthDay calculates the build number based on [monthssincestart][dayofmonth]. BuildDay calculates the build number based on [lastdigitofyear][dayofyear]. Any other value will be used to format the current date/time.
-r --revision Fixed | Automatic | Increment | <date format> The algorithm used to calculate the revision number. Automatic calculates the revision number based on [secsincemidnight/10]. Increment calculates the revision number by incrementing the current revision number by one. Fixed causes the revision number to remain the same. Any other value will be used to format the current date/time.
-p --pin A version number in the x.x.x.x format. The version number to output. The pin option allows you to pin the version number.
-i --inputfile Path to an existing file. The file to use as the input. If the inputfile option is not present the standard input stream is used.
-o --outputfile A valid filename. The file to write to. If not specified, the standard output stream is used.
-w --write N/A Writes the version number (and only the version number) to the output stream.

Return Values

0 UpdateVersion successfully read the input and wrote the output. Note: UpdateVersion returns 0 even when it does not find an AssemblyVersion attribute string to update in the input. If that happens UpdateVersion writes a warning to the standard error stream.
1 UpdateVersion was unable to parse the command line options. See the standard error stream for more information. Note: UpdateVersion does not write to the output when this happens.
2 UpdateVersion was unable to read the input. See the standard error stream for more information. Note: UpdateVersion does not write to the output when this happens.
3 An error occurred while UpdateVersion was searching for the AssemblyVersion attribute or while it was calculating the new version number. See the standard error stream for more information. Note: UpdateVersion does not write to the output when this happens.
4 UpdateVersion was unable to write the output. See the standard error stream for more information. Note: UpdateVersion does not write to the output when this happens.

Usage Examples

Command Line or Batch File

Standard input and standard output

Command Expected Output
C:\>echo AssemblyVersion("1.0.0.0") | UpdateVersion AssemblyVersion("1.0.0.8298")
C:\>echo AssemblyVersion("1.0.0.0") | UpdateVersion -b Increment AssemblyVersion("1.0.1.8310")
C:\>echo AssemblyVersion("1.0.0.0") | UpdateVersion -b Increment -r Increment AssemblyVersion("1.0.1.1")
C:\>echo AssemblyVersion("1.0.0.0") | UpdateVersion -b MonthDay -s 2002-11-23 AssemblyVersion("1.0.23.8335")
C:\>echo AssemblyVersion("1.0.0.0") | UpdateVersion -b MonthDay -s 2000-11-23 AssemblyVersion("1.0.2423.8339")
C:\>echo AssemblyVersion("1.0.0.0") | UpdateVersion -b MonthDay -s 11/23/2000 AssemblyVersion("1.0.2423.8339")
C:\>echo AssemblyVersion("1.0.0.0") | UpdateVersion -p 1.2.3.4 AssemblyVersion("1.2.3.4")
C:\>echo AssemblyVersion("1.0.0.0") | UpdateVersion -b BuildDay AssemblyVersion("1.0.3298.7453")
C:\>echo AssemblyVersion("1.0.0.0") | UpdateVersion -b Increment -r Fixed AssemblyVersion("1.0.1.0")
C:\>echo AssemblyVersion("1.0.0.0") | UpdateVersion -b yyyyMM -r ddHHmm AssemblyVersion("1.0.200910.312105")
C:\>echo AssemblyFileVersion("1.0.0.0") | UpdateVersion -v File AssemblyFileVersion("1.0.0.7517")

Redirecting to and from standard input and standard output

C:\>UpdateVersion -b Increment < Input.txt > Output.txt

Specify the input and output files on the command line

C:\>UpdateVersion -b Increment -i Input.txt -o Output.txt

You can mix and match all of these techniques so you could easily specify an input file on the command line and write the output to standard output like so:
C:\>UpdateVersion -b Increment -i Input.txt

To specify the output file on the command line and read the input from standard input do this:
C:\>echo AssemblyVersion("1.0.0.0") | UpdateVersion -b Increment –o Output.txt

Use UpdateVersion with Visual Studio

You can add UpdateVersion to the Tools menu as an External Tool. You can then select the UpdateVersion command from the menu to update your AssemblyInfo.* file. Just select Tools > External Tools... > Add and enter values similar to the following:

Title: Update Version Number
Command: UpdateVersion.exe
Arguments: -b MonthDay -s 2002-11-23 -i "AssemblyInfo.cs" -o "AssemblyInfo.cs"
Initial directory: $(ProjectDir)
Use Output window: Checked

If UpdateVersion is not in your PATH you will need to provide the full path where UpdateVersion can be found. You can specify any valid options for the arguments.

Use UpdateVersion in a Makefile

Create a new Makefile with the following contents:
test: 
    UpdateVersion -b MonthDay -s 2002-01-21 -i Input.txt -o Output.txt

Then run nmake.

Use UpdateVersion with NAnt

Create a new NAnt script named Test.build with the following contents:
<project name="ExecTest" default="test">
  <tstamp/>
  <target name="test" description="tests using exec to run UpdateVersion.exe">
    <echo message="********************************************************************"/>
    <echo message="** Running UpdateVersion.exe."/>
    <exec program="UpdateVersion.exe" commandline="-b MonthDay -s 2002-01-21 -i Input.txt -o Output.txt" verbose="true" failonerror="true" />
    <echo message="** End of Tests"/>
    <echo message="********************************************************************"/>
  </target>
</project>

Then run NAnt.

Because UpdateVersion returns a non-zero value when it fails your NAnt script will fail as long as the exec tasks' failonerror option is true.

Additional Resources

Last edited Nov 1, 2009 at 2:39 AM by flanakin, version 4

Comments

No comments yet.