Click here to Skip to main content
Click here to Skip to main content

Project Version Updater

, 11 Nov 2011
Rate this:
Please Sign up or sign in to vote.
Updates the AssemblyVersion and FileVersion attributes in the AssemblyInfo file for a project

Introduction

Not satisfied with the versioning capabilities of Visual Studio? Try this tool.

Using the Code

This code does nothing more than read the AssemblyInfo file of your project and updates the version information based upon your selected method. It was basically designed to be run either as an external tool or from build events.

In all examples below, quotes are very important.

Arguments

  • -p = project name
  • -f = project folder
  • -s = version schema

From Command Line

updatever -p="MyProject.vbproj" -f="C:\Documents and Settings\userid\My Documents\
Visual Studio 2008\Projects\ProjectFolder\MyProject" -s="schemaname"

From Visual Studio as an External Tool

  • Start Visual Studio IDE
  • Go to Tools
  • Select External Tools...
  • Click Add
  • Title = Update Version
  • Command = C:\SomeFolder\UpdateVer.exe
  • Arguments = -p="$(ProjectFileName)" -f="$(ProjectDir)" -s="schemaname"
  • Check Use output window
  • Click Ok

As Pre Build Event

  • Start Visual Studio IDE
  • Go To Project properties
  • Click Compile (VB) or Build Events (C#)
  • Click Build Events (VB)
  • In Pre Build event command line box, enter:
    if not $(ConfigurationName) == DEBUG (
    "C:\SomeFolder\UpdateVer.exe" -p="$(ProjectFileName)" 
    -f="$(ProjectDir)"" -s="schemaname" 
    )

Methods

Methods do the actual version revision. Descriptions of the provided methods are given below:

  • ignore - ignores the value and returns current version number
  • increment - increments the current version number
  • incrementeachday - will only increment if the date is greater than the previous version update stored as a comment in the AssemblyInfo file
  • incrementreseteachday - will continue to increment the version number, but will reset that value to 0 if the date is greater than the previous version update
  • random - selects a random version number
  • dayvalue - number of days since 01/01/1900
  • dayvaluefrom - number of days since value specified as a parameter in the level element for the method
  • secondvalue - number of seconds since 01/01/1900
  • secondvaluefrom - number of seconds since value specified as a parameter in the level element for the method
  • fixed - sets to the value specified as a parameter in the level element for the method
  • year - current date year
  • month - current date month
  • day - current date day
  • fromsubversion - updates value from revision in subversion

Combining methods for each version part makes this very flexible. For instance, you can have the following schema:

<schema name="fixed_increment_build_each_day">
    <detail name="assembly/file">
        <level name="major" parameter="2" method="fixed"/>
        <level name="minor" parameter="3" method="fixed"/>
        <level name="build" method="incrementeachday"/>
        <level name="revision" method="incrementreseteachday"/>
    </detail>
</schema>

This will set fixed numbers for the major and minor parts of the version, each day will increment the build, and revision will increment on each compile, but each day will reset to 0. Thus, you may have version 2.3.15.5, compile 5 times during the day, making the version 2.3.15.10, but the next day on the first compile, the version will be 2.3.16.0, because of the increment of the build (for the day) and the reset of the revision. If you want to keep track of the day of the compile, you could change the build method to "dayvalue" and you will always know what day it was compiled on. This schema also keeps the assembly and file versions synchronized, provided they started out the same.

Version number methods are hard-coded in the UpdateMethods.vb file. I have provided the source code, so if you have some others you would like to use, code them and recompile. You will also need to add a call to the method in the ProcessMethod method of the ProjectData class to make the call to the newly created method.

Please share any new methods source here for others to use and they will be included in a future release. I will update the code occasionally with new methods and/or schemas.

Schemas

Several pre-defined schemas are provided. You can create more... just add them to the VersionSchemas.xml file.

You can specify assembly and file versions to use different methods by specifying "assembly" and "file" as the name in two different detail sections for the schema. If you want to use the same for assembly and file versions, specify "assembly/file" as the name. To keep assembly and file versions synchronized, ensure the versions are identical before calling.

Updates

04/20/2011

You can now specify the schema in the project file. Place the following element somewhere into the root project element:

  <projectextensions>
    <compile name="UpdateVersion">
<[CDATA[
<schema name="fixed_increment_build_each_day">
    <detail name="assembly/file">
        <level name="major" parameter="2" method="fixed"/>
        <level name="minor" parameter="3" method="fixed"/>
        <level name="build" method="incrementeachday"/>
        <level name="revision" method="incrementreseteachday"/>
    </detail>
</schema>
]]>

This allows you to keep the version update methods with the project instead of in the VersionSchemas.xml file. This also ensures the same schema will be used if the project is being shared amongst multiple developers with this application installed.

04/27/2011

Added new method (FromSubversion) (as suggested by Steve Pinckney) for subversion support.

Thanks to the SharpSVN project on CollabNet for the binaries for subversion.

11/11/2011

Errors occur if you don't change the version number from the default 1.0.* to 1.0.0.0 when a new project is created. Also, Visual Studio 2010, I have noticed, when creating some AssemblyInfo files, calls the AssemblyFileVersion entry AssemblyFileVersionAttribute. If you receive errors when running the application, check this to see if this is the case. Just change it to AssemblyFileVersion and everything works okay.

Unusual Behavior

When using as an external tool operating on the existing project, an exception will be thrown if the AssemblyInfo file is not displayed in the IDE. If you display the file in the editor and run the application as an external tool, no exception will be thrown and the AssemblyInfo file will be updated properly. I would have thought it would be the other way around. Evidently the IDE keeps that file exclusively open when not being edited, but removes the lock when it is being edited. Anyway, if you are using it as a tool, keep this in mind.

Points of Interest

Nothing really interesting about the code. Just thought I'd provide it in case others wanted to use it.

History

  • Original: 04/19/2011
  • Update: 04/20/2011 - Added ability to place schema into the project file
  • Update: 04/27/2011 - Subversion revision support

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Greg Osborne

United States United States
Visual Basic Developer since version 1.0
Java web developer
Currently developing in vb and c#

Comments and Discussions

 
GeneralUseful PinmemberBrisingr Aerowing22-Feb-13 8:07 
GeneralMy vote of 5 PinmemberAbinash Bishoyi11-Nov-11 19:54 
GeneralRe: My vote of 5 PinmemberGreg Osborne13-Nov-11 9:40 
GeneralGood PinmemberCIDev13-May-11 6:52 
GeneralGood one PinmemberShahriar Iqbal Chowdhury27-Apr-11 10:35 
GeneralNew Method Request: fromSVN PinmemberMember 49546826-Apr-11 10:30 
AnswerRe: New Method Request: fromSVN PinmemberGreg Osborne27-Apr-11 2:28 
GeneralRe: New Method Request: fromSVN PinmemberGreg Osborne27-Apr-11 6:54 
GeneralRe: New Method Request: fromSVN PinmemberSteve Pinckney27-Apr-11 7:23 
GeneralRe: New Method Request: fromSVN PinmemberSteve Pinckney27-Apr-11 7:26 
GeneralRe: New Method Request: fromSVN PinmemberGreg Osborne27-Apr-11 7:56 
GeneralRe: New Method Request: fromSVN PinmemberGreg Osborne27-Apr-11 8:34 
GeneralMy vote of 5 Pinmemberrrusson26-Apr-11 5:50 
GeneralMy vote of 5 PinmemberMustafa M. Gamal26-Apr-11 1:36 
GeneralHow does it compare to UpdateVersion? Pinmemberxoox19-Apr-11 10:45 
GeneralRe: How does it compare to UpdateVersion? PinmemberGreg Osborne20-Apr-11 2:20 
GeneralRe: How does it compare to UpdateVersion? PinmemberGreg Osborne20-Apr-11 3:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 11 Nov 2011
Article Copyright 2011 by Greg Osborne
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid