Get company name and copyright information of assembly [duplicate]

ε祈祈猫儿з 提交于 2019-12-04 16:22:24

问题


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?


回答1:


You can use FileVersionInfo like this:

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

var companyName = versionInfo.CompanyName;



回答2:


From this answer for 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).




回答3:


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

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

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


来源:https://stackoverflow.com/questions/19384193/get-company-name-and-copyright-information-of-assembly

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