Over a million developers have joined DZone.

Automatic Version Increment for Windows Phone Apps

· Mobile Zone

Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud, brought to you in partnership with IBM.

Version increment for Windows Phone projects currently has to be done manually, as developers are updating the version attribute in the WMAppManifest.xml file. Whenever I install the application I am currently working on, I am always wondering whether the Windows Phone device has the most recent build available. With a static version, this becomes a challenge because often changes are not visual, but are done in the background.

As there are no built-in version increment capabilities, I developed a very simple console application that is ran before the building process, modifying the current value in the WMAppManifest.xml file. Here is the source - it is as simple as it can get:

using System;
using System.Linq;
using System.Xml;

namespace WPVersionIncrementer
    class Program
        static void Main(string[] args)
            if (args.Count() == 5)
                // Separate all parameters. If there aren't five of them, ignore execution.
                string path = args[0];
                string incrementMajor = args[1];
                string incrementMiddle = args[2];
                string incrementMinor = args[3];
                string incrementBuild = args[4];

                XmlDocument document = new XmlDocument();

                XmlNode node = document.DocumentElement;
                XmlNode appNode = node["App"];

                string rawVersion = appNode.Attributes["Version"].Value.ToString();
                string[] components = rawVersion.Split(new char[] { '.' });

                // Get integer values for all four version components for easy manipulation
                // read: increment
                int major,middle,minor,build;

                int.TryParse(components[0], out major);
                int.TryParse(components[1], out middle);
                int.TryParse(components[2], out minor);
                int.TryParse(components[3], out build);

                if (incrementMajor.ToLower() == "-i")

                if (incrementMiddle.ToLower() == "-i")

                if (incrementMinor.ToLower() == "-i")

                if (incrementBuild.ToLower() == "-i")

                // Compose the new version in a unified string and save it. The order of all components
                // is preserved.
                string compositeNewVersion = string.Format("{0}.{1}.{2}.{3}", major, middle, minor, build);
                appNode.Attributes["Version"].Value = compositeNewVersion;


To actually perform the increment, right-click on the Windows Phone project in the Solution Explorer and select Properties. Select Build Events and use this for the Post-build event command line:

"C:\Users\Dennis\Documents\Visual Studio 2010\Projects\WPVersionIncrementer\WPVersionIncrementer\bin\Release\WPVersionIncrementer.exe" "$(ProjectDir)Properties\WMAppManifest.xml" -n -n -n -i

There are several things I have to mention here:

  • The path may vary - depending where WPVersionIncrementer is located, you might want to change the location in the command above. 
  • Use quotes for the path - if you know that the executable location contains folder names composed of two or more words separated by a space, you need the quotes for the path to be correctly recognized.
  • Use 5 parameters - even if you need to only increment the build number, indicate that you do not need to increment other indicators. For example, you can use a command like this: WPVersionIncrementer PATH_TO_XML -n -n -i -i Only the -i parameter is recognizes as a flag to increment the value. The parameters are structured in order of the version string: Major, Middle, Minor, Build.
  • Use the Properties folder to modify WMAppManifest.xml and NOT Debug or Release, where it is also found, but in fact - copied at build time from Properties.

After the command is executed and you return to Visual Studio, you will be notified that one file in the project was modified and needs to be reloaded:

Now that WMAppManifest has an updated version, you can always read it internally and display in the About screen or wherever you want in your application.

Recommended reading:  Read Local XML File in Windows Phone 7

You can download the experimental source code here.

The Mobile Zone is brought to you in partnership with Strongloop and IBM.  Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud.


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}