在 Silverlight 3.0 应用程序中,我想使用程序集文件版本 http://msdn.microsoft.com/en-us/library/system.reflection.assemblyfileversionattribute.aspx显示应用程序的版本信息。这与汇编版本 http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.aspx通常使用以下代码在 .NET 应用程序中检索:
var executingAssembly = Assembly.GetExecutingAssembly();
var fileVersionInfo = FileVersionInfo.GetVersionInfo(executingAssembly.Location);
var versionLabel = fileVersionInfo.FileVersion;
不幸的是 Silverlight 3.0 运行时不包括文件版本信息 http://msdn.microsoft.com/en-us/library/system.diagnostics.fileversioninfo_members.aspx班级。有其他方法可以访问此信息吗?
这是一种使用属性来做到这一点的方法 - 我不确定它是否可以在 Silverlight 中工作,所以你必须让我知道。
Assembly assembly = Assembly.GetExecutingAssembly();
object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);
if (attributes != null && attributes.Length > 0)
{
AssemblyFileVersionAttribute fileVersionAttribute = (AssemblyFileVersionAttribute)attributes[0];
string version = fileVersionAttribute.Version;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)