Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get the version info from a pro addin
var myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var arcGisProLocation = Path.Combine(myDocs, "ArcGIS", "AddIns", "ArcGISPro");
var attribute = (GuidAttribute) _assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
var proAddinFolder = $"{{{attribute.Value}}}";
var addinFolder = Path.Combine(arcGisProLocation, proAddinFolder);
if (!Directory.Exists(addinFolder))
return null;
// glob for *.esriAddinX
var addins = Directory.GetFiles(addinFolder, "*.esriAddinX");
if (!addins.Any())
throw new ArgumentOutOfRangeException($"Could not find the addin in {addinFolder}");
if (addins.Length > 1)
throw new ArgumentOutOfRangeException($"Multiple esriAddinX files in {addinFolder}");
var addin = addins.FirstOrDefault();
var entry = ZipFile.OpenRead(addin)
.Entries
.FirstOrDefault(x => x.Name.Equals("config.daml", StringComparison.InvariantCultureIgnoreCase));
if (entry == null)
throw new ArgumentException("Could not find config.daml");
var text = new string(
new StreamReader(
entry
.Open(), Encoding.UTF8)
.ReadToEnd()
.ToArray());
var xmlDoc = XDocument.Parse(text);
var ns = XNamespace.Get("http://schemas.esri.com/DADF/Registry");
var addInInfo = xmlDoc.Root?.Element(ns + "AddInInfo");
if (addInInfo == null)
throw new ArgumentException("could not find AddInInfo xml element");
var name = addInInfo.Element(ns + "Name");
return new VersionInformation(name?.Value, addInInfo.Attributes().Single(x => x.Name == "version").Value,
addInInfo.Attributes().Single(x => x.Name == "desktopVersion").Value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.