Reading the version from a ClickOnce .application file

ClickOnce .application files contain an assemblyIdentity element with a version attribute:

<?xml version="1.0" encoding="utf-8"?>
...
  <assemblyIdentity name="Simple Data Logger.application" version="1.1.2.1" publicKeyToken="0c3a74e9157b5601" language="en" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />

An easy way to read this version string is:

var assembly = XElement.Load(uri);
XNamespace ns = "urn:schemas-microsoft-com:asm.v1";
remoteVersionString = assembly.Element(ns + "assemblyIdentity").Attribute("version").Value;

You can use this to create a Version object:

var version = new Version(remoteVersionString);

Note: The code above runs synchronously and blocks your application. To avoid this, you could run it in as a task on the thread pool with Task.Run() or you could use XElement.LoadAsync instead of XElement.Load(), if available.

Leave a Reply

Your email address will not be published. Required fields are marked *