38

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?

Michael
  • 57,169
  • 9
  • 80
  • 125
Computer User
  • 2,839
  • 4
  • 47
  • 69
  • 2
    http://stackoverflow.com/q/1626801/1324019 – Mansfield Oct 15 '13 at 14:48
  • I see [lots of useful stuff](https://www.google.com/search?q=c%23+get+assembly+company+name+copyright&oq=c%23+get+assembly+company+name+copyright&aqs=chrome..69i57j69i58.5195j0j7&sourceid=chrome&espv=210&es_sm=93&ie=UTF-8) with a Google search. Have you tried anything? – tnw Oct 15 '13 at 14:48

3 Answers3

68

You can use FileVersionInfo like this:

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

var companyName = versionInfo.CompanyName;
Alessandro D'Andria
  • 8,663
  • 2
  • 36
  • 32
  • 2
    This answer might not work with "Single File" published assemblies. (see for help: https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file ) – Rhaokiel Jan 19 '21 at 21:24
  • Maybe, the answer were thought mainly for full (old) .NET Framework. – Alessandro D'Andria Jan 19 '21 at 21:44
  • 2
    Yeah, just letting others who may have come here looking for an answer (like me) find what they need faster. It took me a couple hours to figure out why this was working in debug, but not after publishing. – Rhaokiel Jan 19 '21 at 21:46
16

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;
}

Code is similar for the copyright, use AssemblyCopyrightAttribute instead of AssemblyCompanyAttribute.

robnick
  • 1,720
  • 17
  • 27
George Duckett
  • 31,770
  • 9
  • 95
  • 162
5

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;
}
Mike Dinescu
  • 54,171
  • 16
  • 118
  • 151