如何在 Windows Phone 中获取应用程序版本? [英] How to get app version in Windows Phone?

查看:26
本文介绍了如何在 Windows Phone 中获取应用程序版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C# 中,可以使用 System.Version.Assembly 获取正在运行的应用程序的版本.但是,这在 Silverlight for Windows Phone 中似乎不存在.有没有替代方案?

In C# one can use System.Version.Assembly to get the version of a running app. However this doesn't appear to exist in Silverlight for Windows Phone. Is there an alternative?

推荐答案

我不知道@henry 是如何接受答案的,因为所有答案都在谈论 Dll 版本,但是当有人谈论获取 Windows Phone 应用程序的版本时,这意味着市场上的应用程序版本.我不知道其他人,但我真的不关心 dll 的版本,而且我使用市场版本来标记源代码管理中的源代码.

I don't how @henry accepted the answer because all answers are talking about Dll version but when one is talking about getting the version of windows phone app that means version of app on the market. I don't know about others but I really don't care about the version of dll and also I use market version to label the source in source control.

当开发者在市场上上传 XAP 时,他/她指定的 XAP 版本可能与 dll 版本不同,同时处理市场从 WMAppManifest.xml 文件中读取信息并写回您在 XAP 提交页面上指定的版本.

When a developer upload XAP on the market he/she specifies the version of XAP which can be different then the dll version, while processing Market reads information from WMAppManifest.xml file and write backs the version you specify on the XAP submission page.

因此,您可以通过 XmlReader 读取 WMappManifest.xml 文件中的所需版本,如下所示;

So the desired version is available in WMappManifest.xml file which you can read by XmlReader like following;

    public static string GetAppVersion()
    {
        var xmlReaderSettings = new XmlReaderSettings
        {
            XmlResolver = new XmlXapResolver()
        };

        using (var xmlReader = XmlReader.Create("WMAppManifest.xml", xmlReaderSettings))
        {
            xmlReader.ReadToDescendant("App");

            return xmlReader.GetAttribute("Version");
        }
    }

这是示例 WMAppManifest.xml

Here is sample WMAppManifest.xml

<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2012/deployment" AppPlatformVersion="8.0">
  <DefaultLanguage xmlns="" code="en-US"/>
  <App xmlns="" ProductID="{cc18507d-0de0-42d6-8b0f-05addeafd21e}" Title="CaledosLab.Phone.ContosoLogTest" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal"  Author="CaledosLab.Phone.ContosoLogTest author" Description="Sample description" Publisher="CaledosLab.Phone.ContosoLogTest" PublisherID="{a204adfc-7718-4c4a-afb4-c1c39ec50d30}">
  </App>
</Deployment>

所以你可以从 App xml 标签中读取任何你想要的信息,就像我们从 app 标签中读取版本一样.例如发布商 ID 或产品 ID

So you can read whatever information you want from App xml tag the same way as we read version from app tag. e.g. publisher Id or Product Id

这篇关于如何在 Windows Phone 中获取应用程序版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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