Reputation: 42175
Is it possible to get the version of the app while it's running?
In a Windows desktop application I can get it as follows:
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
But GetExecutingAssembly()
isn't available in Windows Phone 8.1.
Is there another way?
Upvotes: 4
Views: 2380
Reputation: 726
For some reason, the answer above does not work on my project ( maybe because I'm running Windows Phone 10 and the app being targeted for Windows Phone 8.1 ). Since there is people who might have this error too, I'll leave here the solution I've 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 );
As for an example, while I had [assembly: AssemblyVersion( "0.1.*" )]
on my AssemblyInfo.cs
, which would generate a Build and Revision numbers for me, with the Package.Current.Id.Version
I would get 0.1.0.0
whilst with the method I described above I get 0.1.5918.18756
.
Upvotes: 0
Reputation: 42175
This is how:
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);
Upvotes: 20