How to get the version of Windows Phone 8.1 application in code?

Can I get the version of the application while I work?

In a windows desktop application, I can get it like this:

System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

But GetExecutingAssembly()not available on Windows Phone 8.1.

Is there another way?

+4
source share
2 answers

Here's how to do it:

PackageVersion pv = Package.Current.Id.Version;
Version version = new Version(Package.Current.Id.Version.Major, 
    Package.Current.Id.Version.Minor, 
    Package.Current.Id.Version.Revision, 
    Package.Current.Id.Version.Build);
+20
source

For some reason, the above answer does not work on my project (possibly because I am running Windows Phone 10 and the application is for Windows Phone 8.1). Since there are people who may also have this error, I will leave here the solution that I found for my case.

Type
    type = typeof( App );
TypeInfo
    typeInfo = type.GetTypeInfo();
Assembly
    assembly = typeInfo.Assembly;
AssemblyName
    assemblyName = assembly.GetName();
Version
    version = assemblyName.Version;

String
    versionString = String.Format( "{0}.{1}.{2}.{3}",
        version.Major,
        version.Minor,
        version.Build,
        version.Revision );

Or in a simplified way:

Version
    version = typeof( App ).GetTypeInfo().Assembly.GetName().Version;

String
    versionString = String.Format( "{0}.{1}.{2}.{3}",
        version.Major,
        version.Minor,
        version.Build,
        version.Revision );

, [assembly: AssemblyVersion( "0.1.*" )] AssemblyInfo.cs, Build Revision, Package.Current.Id.Version 0.1.0.0, get 0.1.5918.18756.

0

All Articles