Assmebly and File Version Information in WinRT

Assembly and File Version Information in WinRT

How to get the assembly and file version information in WinRT apps

Short and simple post this time. If you need to get the assembly and file version information in your Windows Store app, here is what you need. Note that the using System.Reflection is important since the GetTypeInfo() method is an extension method in that namespace.

using System;
using System.Reflection;

namespace Example
{
    public class VersionInformation
    {
        public VersionInformation()
        {
            var assembly = this.GetType().GetTypeInfo().Assembly;
            var assemblyVersion = assembly.GetName().Version.ToString();
            var fileVersion = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
            var productVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
            System.Diagnostics.Debug.WriteLine("Assembly Version: " + assemblyVersion);
            System.Diagnostics.Debug.WriteLine("File Version: " + fileVersion);
            System.Diagnostics.Debug.WriteLine("Product Version: " + productVersion);
        }
    }
}

Similar, but slightly different than in other versions of .NET since Assembly.GetExecutingAssembly() and System.Diagnostics.FileVersionInfo are not available. Hope that helps somebody out.