[Tip] Python snippet increases the UWP product version

If you have a C# project and want to manage the assembly version info during automation build process such as the msbuild with Jenkins, then two options are available:

  1. Specify the version number in AssemblyInfo.cs to with asterisk(*) – n.n.* (for example, ‘1.0.*’)
  2. Or you might want to manage it with a build script such as python or powershell.

Here is a python build script to manage the version string within AssemblyInfo.cs and Package.appxmanifest.


def set_package_version(manifest_file, target_version):
from xml.etree import ElementTree as et
et.register_namespace("", "http://schemas.microsoft.com/appx/manifest/foundation/windows10")
et.register_namespace("mp","http://schemas.microsoft.com/appx/2014/phone/manifest")
et.register_namespace("uap", "http://schemas.microsoft.com/appx/manifest/uap/windows10")
tree = et.parse(manifest_file)
e = tree.find('{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Identity')
e.attrib['Version'] = target_version
tree.write(manifest_file, xml_declaration=True, encoding='utf-8')


import re
import sys
def set_version(infocs, target_version):
if not infocs or not target_version:
raise Exception('invalid param')
return
with open(infocs, "r+") as f:
assemblyinfo_cs = f.read()
pattern_1 = re.compile(r'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', re.MULTILINE)
pattern_2 = re.compile(r'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', re.MULTILINE)
sub1 = r'AssemblyVersion("{}")'.format(target_version)
sub2 = r'AssemblyFileVersion("{}")'.format(target_version)
phase_1 = re.sub(pattern_1, sub1, assemblyinfo_cs)
phase_2 = re.sub(pattern_2, sub2, phase_1)
f.seek(0)
f.write(phase_2)
f.truncate()

view raw

setversion.py

hosted with ❤ by GitHub

Thanks,

Heejune

One thought on “[Tip] Python snippet increases the UWP product version

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s