Silverlight 3 alternative to FileVersionInfo.GetVersionInfo

白昼怎懂夜的黑 提交于 2019-12-05 11:39:44

Here's a way to do it with attributes - I'm not sure if it will work in Silverlight though so you'll have to let me know.

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;
}

I found a solution to this in a twitter post by Craig Young (courtesy of Google's page caching) using Assembly.GetCustomAttributes as follows

var executingAssembly = Assembly.GetExecutingAssembly();
var customAttributes = executingAssembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);
if (customAttributes != null)
{
   var assemblyFileVersionAttribute = customAttributes[0] as AssemblyFileVersionAttribute;
   var fileVersionLabel = assemblyFileVersionAttribute.Version;
}

Posting this solution for future reference.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!