Tuesday 4 July 2017

arcgis 10.0 - Is there a way to automatically increment the Version value in the Config.esriaddinx file?


I don't think there is an out-of-the-esri-box way to do this, but has anyone hacked up a way to change this value automatically for a build? Perhaps using a pre-build event command?



Answer



The Python option works for me:


c:\Python26\ArcGIS10.0\python.exe C:\sandbox\py\misc\UpdateAddInVersionNumber.py "$(ProjectDir)Config.esriaddinx"


enter image description here


(Python gurus, feel free to jump in and make it better) UpdateAddInVersionNumber.py:


import os, sys
import xml.dom.minidom

import datetime

filename = sys.argv[1]
print filename

b = 0

doc = xml.dom.minidom.parse(filename)

tags = doc.getElementsByTagName('Version')


if (len(tags)==1):
currentNodeValue = tags[0].childNodes[0].toxml()
tokens = currentNodeValue.split('.')
lastToken = tokens[len(tokens) -1]
if lastToken.isnumeric():
i = int(lastToken)
i +=1
tokens[len(tokens) -1] = str(i)
newVersionNumberValue='.'.join(tokens)

tags[0].childNodes[0].nodeValue = newVersionNumberValue
b = 1
print newVersionNumberValue


tags = doc.getElementsByTagName('Date')
if (len(tags)==1):
tags[0].childNodes[0].nodeValue =datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
b = 1
print tags[0].childNodes[0].nodeValue


if (b==1):
f = open(filename,'wb')
doc.writexml(f,encoding= 'utf-8')
f.close()

sys.exit()

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...