【发布时间】:2013-10-23 10:23:12
【问题描述】:
我正在使用Assembly.GetEntryAssembly().GetName() 获取应用程序/程序集名称及其版本,但我没有看到公司名称和版权的任何变量。我怎么得到它?
【问题讨论】:
-
我通过 Google 搜索看到了 lots of useful stuff。你有没有尝试过?
标签: c# .net .net-assembly
我正在使用Assembly.GetEntryAssembly().GetName() 获取应用程序/程序集名称及其版本,但我没有看到公司名称和版权的任何变量。我怎么得到它?
【问题讨论】:
标签: c# .net .net-assembly
你可以像这样使用FileVersionInfo:
var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);
var companyName = versionInfo.CompanyName;
【讨论】:
来自this answer的公司名称:
Assembly currentAssem = typeof(CurrentClass).Assembly;
object[] attribs = currentAssem.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true);
if(attribs.Length > 0)
{
string company = ((AssemblyCompanyAttribute)attribs[0]).Company
}
版权类似。 (使用AssemblyCopyrightAttribute)。
【讨论】:
这些是您必须使用反射在 Assembly 对象上枚举的属性。
var attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
var attribute = null;
if (attributes.Length > 0)
{
attribute = attributes[0] as AssemblyCompanyAttribute;
}
【讨论】: