在一个Silverlight 3.0应用程序,我想使用的AssemblyFileVersion为显示应用程序的版本信息。这是不一样的AssemblyVersion和一般检索在.NET应用程序中使用code,如:
Within a Silverlight 3.0 application I want to use the AssemblyFileVersion to display the version information of the application. This is not the same as the AssemblyVersion and is typically retrieved in a .NET application using code such as:
var executingAssembly = Assembly.GetExecutingAssembly();
var fileVersionInfo = FileVersionInfo.GetVersionInfo(executingAssembly.Location);
var versionLabel = fileVersionInfo.FileVersion;
不幸的Silverlight 3.0运行时不包括FileVersionInfo类。有没有访问此信息的另一种方式?
Unfortunately Silverlight 3.0 runtime does not include the FileVersionInfo class. Is there an alternative way to access this information?
推荐答案
我发现克雷格解决这个在Twitter发布年轻(礼貌谷歌的页面缓存)使用 Assembly.GetCustomAttributes 的如下:
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.
相关推荐
最新文章