How to get AssemblyTitle in C#

By FoxLearn 10/25/2024 8:56:01 AM   59
In C#, you can retrieve the assembly title from the assembly attributes using reflection.

The AssemblyTitle attribute is typically defined in the AssemblyInfo.cs file.

string title = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyTitleAttribute>().Title;

Or

// Get the current assembly
var assembly = Assembly.GetExecutingAssembly();

// Get the AssemblyTitle attribute
var titleAttribute = assembly.GetCustomAttribute<AssemblyTitleAttribute>();

if (titleAttribute != null)
{
      string title = titleAttribute.Title;
}

The Assembly.GetExecutingAssembly() method gets the assembly that contains the code that is currently executing.

GetCustomAttribute<AssemblyTitleAttribute>() retrieves the title attribute from the assembly.

Make sure to include the necessary using directive for System.Reflection.