Retrieve the Current App version from Package
Asked Answered
C

1

55

While I can get the assembly version using the following code

        var assembly = typeof(App).GetTypeInfo().Assembly;
        var assemblyVersion = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;

I would like to retrieve the Version from Package.appxmanifest in this case 1.0.0.4

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest">
  <Identity Name="zzz" Publisher="CN=zzz" Version="1.0.0.4" />

I expected to have access to Windows.ApplicationModel, but this is not available to me

Confidence answered 20/2, 2015 at 17:52 Comment(1)
possible duplicate of How can I get my Windows Store app's title and version info?Curse
C
139

Here's what you can do to retrieve the version in code:

using Windows.ApplicationModel;

public static string GetAppVersion()
{
  Package package = Package.Current;
  PackageId packageId = package.Id;
  PackageVersion version = packageId.Version;

  return string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);
}

Reference: http://www.michielpost.nl/PostDetail_67.aspx

Chromatophore answered 20/2, 2015 at 18:8 Comment(6)
Perfect! Cheers @Kevin!Confidence
@ChrisBallance you're welcome ! Always a pleasure to help a follow dev !Chromatophore
Do you also know how to retrieve the package description? Package.Current.Description is empty at runtime ...Allotrope
app version is different when it is installed on xBox. do you know why?Fissile
Was not different on Xbox for meAffirm
If you're seeing different version on different platforms, double check that the package deployment is targeting those platforms. You'll see a row of checkboxes on the Packages step.Guayule

© 2022 - 2024 — McMap. All rights reserved.