从类库中检索AssemblyCompanyName

Bla*_*ell 21 .net c#

我想从我的C#类库中的WinForm项目中获取AssemblyCompany属性.在WinForms中,我可以使用以下方式获取此信息:

Application.CompanyName;
Run Code Online (Sandbox Code Playgroud)

但是,我似乎找不到使用类库获取相同信息的方法.你能提供的任何帮助都会很棒!

Rex*_*x M 28

要获取当前代码(类库代码)实际所在的程序集,并读取其公司属性:

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

  • 我发现它非常有用!如果您使用的是新的.NET版本,则可以使用typeof(CurrentClass).Assembly.GetCustomAttribute <AssemblyCompanyAttribute>().Company (2认同)

Mik*_*all 7

您可以使用FileVersionInfo类来获取更多CompanyName.

    Dim info = FileVersionInfo.GetVersionInfo(GetType(AboutPage).Assembly.Location)
    Dim companyName = info.CompanyName
    Dim copyright = info.LegalCopyright
    Dim fileVersion = info.FileVersion
Run Code Online (Sandbox Code Playgroud)