C# 获取程序集的公司名称和版权信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19384193/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 14:51:29  来源:igfitidea点击:

Get company name and copyright information of assembly

c#.net.net-assembly

提问by Computer User

I am using Assembly.GetEntryAssembly().GetName()to get application/assembly name and its version but I do not see any variable for company name and copyright. How do I get that?

我正在使用Assembly.GetEntryAssembly().GetName()获取应用程序/程序集名称及其版本,但我没有看到公司名称和版权的任何变量。我怎么得到它?

采纳答案by Alessandro D'Andria

You can use FileVersionInfolike this:

您可以像这样使用FileVersionInfo

var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);

var companyName = versionInfo.CompanyName;

回答by Mike Dinescu

Those are attributes that you have to enumerate on the Assembly object using reflection.

这些是您必须使用反射在 Assembly 对象上枚举的属性。

var attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);

var attribute = null;
if (attributes.Length > 0)
{
    attribute = attributes[0] as AssemblyCompanyAttribute;
}

回答by George Duckett

From this answerfor the company name:

这个公司名称的答案中:

Assembly currentAssem = typeof(CurrentClass).Assembly;
object[] attribs = currentAssem.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true);
if(attribs.Length > 0)
{
    string company = ((AssemblyCompanyAttribute)attribs[0]).Company
}

Similar for the copyright. (Use the AssemblyCopyrightAttribute).

版权类似。(使用AssemblyCopyrightAttribute)。