49

虽然我可以使用以下代码获取程序集版本

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

Package.appxmanifest在这种情况下,我想从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" />

我希望可以访问Windows.ApplicationModel,但这对我不可用

4

1 回答 1

123

您可以执行以下操作来检索代码中的版本:

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);
}

参考: http: //www.michielpost.nl/PostDetail_67.aspx

于 2015-02-20T18:08:47.580 回答