Geeks With Blogs
Confessions of an Evangelist

Sometimes you spend a lot of time searching online for an answer, but the truth is that it’s a lot easier just to open up the debugger, spend a few minutes, and find it yourself. In the context of today’s lesson I am working on a Windows 8 application that needs to display the product build number in the About page in the application settings.

I was able to find several documents online that worked for WPF and WinForms application but not much for Windows 8 Store apps which have the limitation of the sandbox they run in. System.Reflection is available, but there doesn’t appear to be an easy way to get to the currently executing assembly to pull the version information from, but I found it in the ApplicationModel.

The code I used to pull out the build version is this:

  string myBuild = Windows.ApplicationModel.Package.Current.Id.Version.Build.ToString()
      + "." + Windows.ApplicationModel.Package.Current.Id.Version.Major.ToString()
      + "." + Windows.ApplicationModel.Package.Current.Id.Version.Minor.ToString()
      + "." + Windows.ApplicationModel.Package.Current.Id.Version.Revision.ToString();

  txtVersion.Text = "Version: " + myBuild;

Simple. Happy coding!

Posted on Wednesday, February 6, 2013 2:50 PM | Back to top

Copyright © Mike Benkovich | Powered by: GeeksWithBlogs.net