How to get app version in Windows Phone?

后端 未结 11 2157
無奈伤痛
無奈伤痛 2020-12-01 13:55

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 alternat

11条回答
  •  佛祖请我去吃肉
    2020-12-01 14:34

    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.

    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.

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

    Here is sample WMAppManifest.xml

    
      
      
      
    
    

    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

提交回复
热议问题