WP8获取应用程序信息

时间:2014-07-27 03:53:12

标签: c# windows-phone-8 version

我正在开发一个需要我的应用程序信息的应用程序(不仅仅是这个应用程序)。具体来说,我需要应用程序名称和版本。我怎么能这样做?

2 个答案:

答案 0 :(得分:1)

您可以使用PackageManager.FindPackages()获取WP8上的应用程序及其信息列表。

public static int Main(string[] args)
{
    PackageManager packageManager = new PackageManager();

    IEnumerable<Windows.ApplicationModel.Package> packages = 
        (IEnumerable<Windows.ApplicationModel.Package>) packageManager.FindPackages();

    int packageCount = 0;
    foreach (var package in packages)
    {
        DisplayPackageInfo(package);

        packageCount += 1;
    }

    if (packageCount < 1)
    {
        Console.WriteLine("No packages were found.");
    }
}

private static void DisplayPackageInfo(Windows.ApplicationModel.Package package)
{
    Console.WriteLine("Name: {0}", package.Id.Name);

    Console.WriteLine("FullName: {0}", package.Id.FullName);

    Console.WriteLine("Version: {0}.{1}.{2}.{3}", package.Id.Version.Major, package.Id.Version.Minor,
        package.Id.Version.Build, package.Id.Version.Revision);

    Console.WriteLine("Publisher: {0}", package.Id.Publisher);

    Console.WriteLine("PublisherId: {0}", package.Id.PublisherId);

    Console.WriteLine("Installed Location: {0}", package.InstalledLocation.Path);

    Console.WriteLine("IsFramework: {0}", package.IsFramework);
}

答案 1 :(得分:0)

我建议解析WMAppManifest.xml 代码将是

using System.Xml.Linq;

string version = XDocument.Load("WMAppManifest.xml").Root.Element("App").Attribute("Version").Value;
// similarly for Title