从包中检索当前应用程序版本 [英] Retrieve the Current App version from Package

查看:107
本文介绍了从包中检索当前应用程序版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

While I can get the assembly version using the following code

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

在这种情况下,我想从Package.appxmanifest中检索版本: 1.0.0.4

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" />

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

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

推荐答案

您可以按照以下步骤在代码中检索版本:

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

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

这篇关于从包中检索当前应用程序版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆