UpdateVersion User Guide

Download UpdateVersion

Overview

UpdateVersion searches its input for a .NET AssemblyVersion attribute and calculates a new version number using one of several algorithms. UpdateVersion can use a file or the standard input stream for input and it can write its output to a file or the standard output stream.

UpdateVersion calculates and outputs new version numbers using one of several algorithms. You can use it with Visual Studio .NET to update your AssemblyInfo.* file on demand. You can use it from a NAnt script to update your assembly version numbers every time you build your project. You can also run it directly from the command line, in a batch file, or from a make file.

UpdateVersion will calculate a new revision number only or it can calculate a new build number and a new revision number at the same time.

UpdateVersion can calculate the build number by incrementing the existing build number or it can calculate the build number based on the project start date.

UpdateVersion can calculate the revision number by incrementing the existing revision number or it can calculate the revision number based on the number of seconds since midnight.

Revision History

Version 1.2

Matt Griffith - http://mattgriffith.net

·         Added Version option.

·         Attempted to improve Unicode handling by outputting to file using the default encoding.

Scott Hanselman - http://www.hanselman.com/blog/

·         Added BuildDay algorithm for build number calculation.

·         Added Fixed algorithm for revision number calculation.

·         Updated the Regular expression to handle this condition: [assembly: AssemblyVersionAttribute("1.0.3296.1")]

·         Refactored VersionUpdater.cs.

Version 1.1

Mike Gunderloy - http://www.larkware.com

·         Added the Pin feature.

 

Command Line Options

Short Form

Long Form

Valid Values

Description

-s

--startdate

Any date string which DateTime can parse for the current culture. Example: 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”

Specifies the algorithm UpdateVersion should use 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].

-p

--pin

A version number in the x.x.x.x format.

Specifies the version number UpdateVersion should output. The pin option allows you to pin the version number.

-r

--revision

"Fixed" | "Automatic" | "Increment" |

Specifies the algorithm UpdateVersion should use 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.

-i

--inputfile

Path to an existing file.

The file UpdateVersion should use as the input. If the inputfile option is not present UpdateVersion will use the standard input stream as its input.

-o

--outputfile

A valid filename.

The file UpdateVersion should write its output to. If the outputfile option is not present UpdateVersion will write its output to the standard output stream.

-v

--version

"Assembly" | "File"

Specifies the version number to update. The default is "Assembly" which is backward compatible with previous versions of UpdateVersion. Use "–v Assembly" to update the AssemblyVersion attribute. Use "–v File" to update the AssemblyFileVersion attribute.

 

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:

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

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.cs or AssemblyInfo.vb 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.exe.

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.

posted on 2005-08-28 10:15  RubyPDF  阅读(2395)  评论(0编辑  收藏  举报