在 Universal Apps 的 Windows 專案中加入以下片段
String Message = String.Format("Name: \"{0}\"\n" +
"Version: {1}.{2}.{3}.{4}\n" +
"Architecture: {5}\n" +
"ResourceId: \"{6}\"\n" +
"Publisher: \"{7}\"\n" +
"PublisherId: \"{8}\"\n" +
"FullName: \"{9}\"\n" +
"FamilyName: \"{10}\"\n" +
"IsFramework: \"{11}\"\n" +
"Installed Location: \"{12}\"",
packageId.Name,
version.Major, version.Minor, version.Build, version.Revision,
packageId.Architecture,
packageId.ResourceId,
packageId.Publisher,
packageId.PublisherId,
packageId.FullName,
packageId.FamilyName,
package.IsFramework,
installedLocation.Path);
Debug.WriteLine(Message);
#region 僅在 Windows Store App 中支援
Message = String.Format("Description: \"{0}\"\n" +
"DisplayName: \"{1}\"\n" +
"PublisherDisplayName: \"{2}\"",
package.Description,
package.DisplayName,
package.PublisherDisplayName);
Debug.WriteLine(Message);
#endregion
執行上面的程式片段可以拿到專案 Package.appxmanifest 中的大部份資訊,但如果是將這段程式碼加在 Windows Phone 專案中,會發現 packate.DisplayName、Description、PublisherDisplayName 是不存在的,這點在使用上需額外注意,附上程式碼執行的結果如下
Name: "e310a380-020c-4ce8-b0f3-b452fcb9bfec"
Version: 1.0.0.0
Architecture: Neutral
ResourceId: ""
Publisher: "CN=Ascii"
PublisherId: "agrczrh6an48t"
FullName: "e310a380-020c-4ce8-b0f3-b452fcb9bfec_1.0.0.0_neutral__agrczrh6an48t"
FamilyName: "e310a380-020c-4ce8-b0f3-b452fcb9bfec_agrczrh6an48t"
IsFramework: "False"
Installed Location: "C:\Users\Ascii\Desktop\AppInfo\AppInfo\AppInfo.Windows\bin\Debug\AppX"
Description: ""
DisplayName: "AppInfo.Windows"
PublisherDisplayName: "Ascii"
沒有留言:
張貼留言