Knowing your Metro Style App package details

<strong>This article is written on a pre-release version. Things mentioned below are bound to change in future releases.</strong>

The package details of your application can be read through the Windows.ApplicationModel.Package namespace. So I create a JavaScript blank app with the below code and I see a guid instead of the app name.

image

It turns out VS2011 adds this a guid as the package name when a project is created. You can change it in the package.manifest file to something more sensible.

image

I also added a bunch of other code to read other details about the package.

   1:  function initialize() {
   2:      var appPackage = Windows.ApplicationModel.Package.current;
   3:      var packageId = appPackage.id
   4:      var packageDetails = '';
   5:      packageDetails += 'Full Name: ' + packageId.fullName + '<br/>';
   6:      packageDetails += 'Name: ' + packageId.name + '<br/>';
   7:      packageDetails += 'Family Name: ' + packageId.familyName + '<br/>';
   8:      packageDetails += 'Publisher: ' + packageId.publisher + '<br/>';
   9:      packageDetails += 'PublisherId: ' + packageId.publisherId + '<br/>';
  10:      packageDetails += 'Version: ' + packageId.version.major + '.' +
  11:                          packageId.version.minor + '.' +
  12:                          packageId.version.build + '.' +
  13:                          packageId.version.revision + '<br/>';
  14:      packageDetails += 'Architecture: ' + GetArchitecture(packageId.architecture) + '<br/>';
  15:      packageDetails += 'Installed Location: ' + appPackage.installedLocation.path + '<br/>';
  16:   
  17:      $('#contentDiv').html(packageDetails);
  18:      
  19:  }
  20:   
  21:  function GetArchitecture(architecture) {
  22:      if (architecture == Windows.System.ProcessorArchitecture.arm) {
  23:          return "arm";
  24:      }
  25:      else if (architecture == Windows.System.ProcessorArchitecture.neutral) {
  26:          return "neutral";
  27:      }
  28:      else if (architecture == Windows.System.ProcessorArchitecture.x64) {
  29:          return "x64";
  30:      }
  31:      else if (architecture == Windows.System.ProcessorArchitecture.x86) {
  32:          return "x86";
  33:      }
  34:      else {
  35:          return "";
  36:      }
  37:  }
  38:   
  39:  document.addEventListener("DOMContentLoaded", initialize, false);

Here’s the output:

image

The full name is a combination of a few other properties like name, version, architecture and the publisher id.

The only thing that needs some explanation is the GetArchitecture function. There seems to be some issue with JavaScript and enums. If I had just written the architecture value on the page, I get an integer there (getting 11 for neutral). This is the integer value for the enum. Hence I’m having to do a check though the GetArchitecture function. The quirk here is that this is only needed for JavaScript as C# handles enums pretty well.

The C# version of the same code is as below:

   1:  void BlankPage_Loaded(object sender, RoutedEventArgs e)
   2:  {
   3:      Windows.ApplicationModel.Package package = Windows.ApplicationModel.Package.Current;
   4:              
   5:      Windows.ApplicationModel.PackageId packageId = package.Id;
   6:      StringBuilder packageDetails = new StringBuilder();
   7:      packageDetails.AppendFormat("Full Name: {0}\n", packageId.FullName);
   8:      packageDetails.AppendFormat("Name: {0}\n", packageId.Name);
   9:      packageDetails.AppendFormat("Family Name: {0}\n", packageId.FamilyName);
  10:      packageDetails.AppendFormat("Publisher: {0}\n", packageId.Publisher);
  11:      packageDetails.AppendFormat("PublisherId: {0}\n", packageId.PublisherId);
  12:      packageDetails.AppendFormat("Version: {0}.{1}.{2}.{3}\n", 
  13:                                                  packageId.Version.Major,
  14:                                                  packageId.Version.Minor,
  15:                                                  packageId.Version.Build,
  16:                                                  packageId.Version.Revision);
  17:      packageDetails.AppendFormat("Architecture: {0}\n", packageId.Architecture);
  18:      packageDetails.AppendFormat("Installed Location: {0}\n", package.InstalledLocation.Path);
  19:   
  20:      Display.Text = packageDetails.ToString();
  21:  }

3 Comments

Comments have been disabled for this content.