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

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

问题描述

在C#中可以使用System.Version.Assembly获得运行的应用程序的版本。然而,这并没有出现在Silverlight中存在的Windows手机。是否有其他选择吗?

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的应用该装置的version应用的版本在市场上。我不知道别人,但我真的不关心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.

因此​​,所需的版本是WMappManifest.xml文件,你可以通过类似的XmlReader阅读下列可用;

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>

所以,你可以看到你的应用程序的XML标记想以同样的方式的任何信息,因为我们读取标签的应用程序版本。例如发行人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天全站免登陆