Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在windows phone 8.0 Silverlight中获取软件包ID_C#_Silverlight_Windows Phone 8 - Fatal编程技术网

C# 如何在windows phone 8.0 Silverlight中获取软件包ID

C# 如何在windows phone 8.0 Silverlight中获取软件包ID,c#,silverlight,windows-phone-8,C#,Silverlight,Windows Phone 8,我有一个windows phone silverlight应用程序8.1,它使用: var Version = Windows.ApplicationModel.Package.Current.Id.Version; 它将成功返回包版本。不幸的是,当我为windows phone silverlight 8.0复制此代码时,我得到了一个“未实现的异常” 我注意到这个信息存储在包清单中,我还注意到在我的8.0单元测试应用程序中没有包清单。我不确定它是否相关或如何修复它,但我认为这些库可能会在那里

我有一个windows phone silverlight应用程序8.1,它使用:

var Version = Windows.ApplicationModel.Package.Current.Id.Version;
它将成功返回包版本。不幸的是,当我为windows phone silverlight 8.0复制此代码时,我得到了一个“未实现的异常”


我注意到这个信息存储在包清单中,我还注意到在我的8.0单元测试应用程序中没有包清单。我不确定它是否相关或如何修复它,但我认为这些库可能会在那里获取这些信息,但不会为SL80实现。请尝试使用此代码从您的
包中获取版本。appxmanifest

Version version = new Version(Package.Current.Id.Version.Major,
                                            Package.Current.Id.Version.Minor,
                                            Package.Current.Id.Version.Build,
                                            Package.Current.Id.Version.Revision);

string packege = version.Build.ToString();
如果您想从
AssemblyInfo.cs
获取版本,请按照以下代码进行编码:

string package = "";
var versionAttribute = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).GetValue(0) as AssemblyFileVersionAttribute;

if (versionAttribute != null)
{
   package = versionAttribute.Version.Tostring();
}