【问题标题】:Is there something like Application.ProductVersion for .NET web DLL?.NET web DLL 是否有类似 Application.ProductVersion 的东西?
【发布时间】:2014-09-04 16:02:04
【问题描述】:
我想获得我的 .NET Web 应用程序或 Web 服务的版本 - 显示在 AssemblyInfo.cs 的 DLL 中的那个 - 并且很高兴获得公司和版权等其他程序集信息。
在 Windows 应用程序中,这很容易,您只需执行 Application.ProductVersion 即可获取版本。 Web 应用程序/服务有类似的东西吗? System.Web.App.Version 之类的东西?
谢谢!
【问题讨论】:
标签:
c#
asp.net
.net
web-services
wcf
【解决方案1】:
对于您想要从中获取版本的程序集中的任何类型,您可以像这样获取版本:
typeof(SomeType).Assembly.GetName().Version
对于其他东西,比如公司和版权,您必须直接查找程序集级属性。以下是版权的示例:
object[] attributes = typeof(SomeType).Assembly
.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
AssemblyCopyrightAttribute attribute = null;
if (attributes.Length > 0)
{
attribute = attributes[0] as AssemblyCopyrightAttribute;
}
var companyName = attribute.Company;