在运行时检查Windows应用商店应用AppxManifest

时间:2015-02-20 13:35:45

标签: windows-runtime windows-phone-8.1 winrt-xaml

我尝试在运行时加载AppxManifest以读出应用版本。我喜欢这篇文章: http://tonychampion.net/blog/index.php/2013/01/examining-the-windows-store-apps-appxmanifest-at-runtime/#comments

我试过帖子中的一行:

var doc = XDocument.Load("AppxManifest.xml", LoadOptions.None);

但这会给我带来以下异常:

{System.Xml.XmlException: An internal error has occurred.
   at System.Xml.XmlXapResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
   at System.Xml.XmlTextReaderImpl.FinishInitUriString()
   at System.Xml.XmlTextReaderImpl..ctor(String uriStr, XmlReaderSettings settings, XmlParserContext context, XmlResolver uriResolver)
   at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
   at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
   at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
   at MyMedi.Src.Utilities.GetVersion()
   at MyMedi.WindowsPhone.Test.Src.UtilitiesTest.Utilities_GetVersionTest()}

谁能告诉我我做错了什么?

由于 NPadrutt

1 个答案:

答案 0 :(得分:2)

我不确定您为什么要这样做,但您可以尝试使用文件参考中的ms-appx:// uri schema加载文档。

但是,有一种更容易实现目标的方法。

Package package = Package.Current;
PackageId packageId = package.Id;
PackageVersion version = packageId.Version;

var versionString = string.Format(
               CultureInfo.InvariantCulture,
               "{0}.{1}.{2}.{3}",
               version.Major,
               version.Minor,
               version.Build,
               version.Revision);