在Silverlight3.0应用程序中,我想使用AssemblyFileVersion来显示应用程序的版本信息。这与AssemblyVersion不同,通常在.NET应用程序中使用如下代码进行检索:
var executingAssembly = Assembly.GetExecutingAssembly();
var fileVersionInfo = FileVersionInfo.GetVersionInfo(executingAssembly.Location);
var versionLabel = fileVersionInfo.FileVersion;不幸的是,Silverlight3.0运行时不包含FileVersionInfo类。有没有其他方法可以访问这些信息?
发布于 2010-01-25 15:06:27
我在Craig Young (感谢谷歌页面缓存)的推特上找到了一个使用Assembly.GetCustomAttributes的解决方案,如下所示
var executingAssembly = Assembly.GetExecutingAssembly();
var customAttributes = executingAssembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);
if (customAttributes != null)
{
var assemblyFileVersionAttribute = customAttributes[0] as AssemblyFileVersionAttribute;
var fileVersionLabel = assemblyFileVersionAttribute.Version;
}发布此解决方案以供将来参考。
发布于 2010-01-25 15:03:56
这里有一个使用属性的方法-我不确定它是否能在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;
}https://stackoverflow.com/questions/2130717
复制相似问题