2

I have made a application to update my other applications. I am using autoupdater.net library to handle the updates. My question is how can I get the version of one application from another?

<?xml version="1.0" encoding="UTF-8"?>
<item>
    <version>1.0.1.0</version> // I would like to update this with the assembly version of another application
    <url></url>
    <changelog></changelog>
    <mandatory mode="2">true</mandatory>
</item>

What this application does is deletes the current zip, zips up the release folder and then the last step would be updating this xml document with the new version number.

  • Does this answer your question? [Modify XML existing content in C#](https://stackoverflow.com/questions/2551307/modify-xml-existing-content-in-c-sharp) – Heretic Monkey Mar 30 '20 at 14:43
  • @HereticMonkey that helps with the edit but then I need to be able to get the version number of the other assembly to write to the note. – user11405709 Mar 30 '20 at 14:44
  • Doing some research on your own would be nice... [Getting the Version of my C# app?](https://stackoverflow.com/q/36351866/215552) – Heretic Monkey Mar 30 '20 at 14:47
  • @HereticMonkey reading the question would be nice... Not trying to get the version number of the application updater application just the version of the application it is updating... – user11405709 Mar 30 '20 at 14:49
  • Considering your question includes no code, and doesn't reference what application is getting what version where. This was a tough one. I had to add "another" to the search phrase "how to get the version of another assembly": [How to get Assembly Version (not File Version) for another EXE?](https://stackoverflow.com/q/2724546/215552) – Heretic Monkey Mar 30 '20 at 14:54

1 Answers1

3

This should work:

XmlDocument doc = new XmlDocument();
doc.Load(@"filepath");

var versionNode = doc.SelectSingleNode("item/version");
versionNode.InnerText = Assembly.GetExecutingAssembly().GetName().Version.ToString();
doc.Save(@"filepath");

You can also load the xml from a string directly if you don't have a file on your disk. Also this gets the version string of the executing assembly. Replace this with the version number if needed.

NoConnection
  • 765
  • 7
  • 23
  • Very close, but I am trying to get the assembly version of a entirely different assembly – user11405709 Mar 30 '20 at 14:50
  • You can also use Assembly.GetAssembly(someTypeInTargetAssembly) to get another assembly version – NoConnection Mar 30 '20 at 14:52
  • 1
    Or if you need to get the version of an assembly without even loading it, try this: https://stackoverflow.com/questions/187999/how-do-i-get-the-version-of-an-assembly-without-loading-it – NoConnection Mar 30 '20 at 14:55
  • 1
    I tested it with the xml you provided, works for me. To navigate through the nodes with SelectSingleNode, you can just use xpath syntax. Here's a list of available options: https://www.w3schools.com/xml/xpath_syntax.asp – NoConnection Mar 30 '20 at 15:29