CodePrairie .NET

South Dakota .NET User Group


Rake task to update version information

I maintain assembly version numbers in my msbuild project files. It is (unfortunately) spread across 3 files for the time being, a .targets file, the master .proj file and a wix (.wxs) file.

So I thought I would hack a quick rake task that will update all these version numbers for me when it comes time to update the application. I ran into a snag though because REXML will by default output attributes like this

<PropertyGroup Condition='$(Configuration) == &apos;&apos;'>

which is not what I want in my msbuild files. I instead want it to look like

<PropertyGroup Condition="$(Configuration) == '' ">

What REXML outputs might still work correctly in MSBUILD, I never tested it, but it will be a lot harder to look at the file and maintain it by hand, so a solution is needed.

Thanks to the flexibility of ruby a solution is not that difficult. I found this post which got me started, then I just need to make a small addition (the Text::unnormalize call)


   REXML::Attribute.class_eval( %q^
def to_string

My complete task looks like this:

task :bump_version do |t|
include REXML
file_names = ["build.proj","project.targets","Install/program/install.wxs"]

build_file, targets_file, install_file = file_names.collect do |file_name|
f =,"r")

major,minor = build_file.root.elements["//ApplicationMajorVersion"].text, build_file.root.elements["//ApplicationMinorVersion"].text

if minor.to_i == 9
major = (major.to_i + 1).to_s
minor = "0"
minor = (minor.to_i + 1).to_s

puts major + "." + minor

build_file.root.elements["//ApplicationMajorVersion"].text = major
build_file.root.elements["//ApplicationMinorVersion"].text = minor

product_el = install_file.root.elements["Product"]
product_el.attributes["Version"] = major + "." + minor + "." + "0.0"
product_el.attributes["Id"] = new_guid[1..-2]
product_el.elements["Upgrade"].each_element do |el|
el.attributes["Minimum"] = product_el.attributes["Version"] unless el.attributes["Minimum"].nil?
el.attributes["Maximum"] = product_el.attributes["Version"] unless el.attributes["Maximum"].nil?

targets_file.root.elements["//AssemblyMajor"].text = major
targets_file.root.elements["//AssemblyMinor"].text = minor

# see: ... slightly modified
REXML::Attribute.class_eval( %q^
def to_string

[build_file, targets_file, install_file].each_with_index do |file, index|[index],'w') { |writeable| file.write(writeable,0) }
Published May 25 2007, 02:09 PM by chrisortman
Filed under:


No Comments

Leave a Comment

Powered by Community Server (Commercial Edition), by Telligent Systems