Your comments help a lot, thanks. I am still having problems retrieving
version information. It all works except the version is never retrieved.
My code looks like this:
public static string title;
public static string description;
public static string configuration;
public static string company;
public static string product;
public static string copyright;
public static string trademark;
public static string name1;
public static string name2;
public static string version;
GetAssemblyAttributes();
....
public static void GetAssemblyAttributes()
{
foreach (object attr in
Assembly.GetExecutingAssembly().GetCustomAttributes(false))
{
AssemblyTitleAttribute aTitle=attr as AssemblyTitleAttribute;
if (aTitle != null) title = aTitle.Title;
AssemblyDescriptionAttribute aDescription=attr as
AssemblyDescriptionAttribute;
if (aDescription != null) description = aDescription.Description;
AssemblyConfigurationAttribute aConfiguration=attr as
AssemblyConfigurationAttribute;
if (aConfiguration != null) configuration =
aConfiguration.Configuration;
AssemblyCompanyAttribute aCompany=attr as AssemblyCompanyAttribute;
if (aCompany != null) company = aCompany.Company;
AssemblyProductAttribute aProduct=attr as AssemblyProductAttribute;
if (aProduct != null) product = aProduct.Product;
AssemblyCopyrightAttribute aCopyright=attr as
AssemblyCopyrightAttribute;
if (aCopyright != null) copyright = aCopyright.Copyright;
AssemblyTrademarkAttribute aTrademark=attr as
AssemblyTrademarkAttribute;
if (aTrademark != null) trademark = aTrademark.Trademark;
AssemblyVersionAttribute aVersion=attr as AssemblyVersionAttribute;
if (aVersion != null) version = aVersion.Version;
}
return;
}
Joe Delekto said:
Greets,
There are several *Attribute classes for the attributes that can be
applied to the assembly. I used the following sample code to extract the
title from the current executing assembly:
public string GetAppTitle()
{
foreach (object attr in
Assembly.GetExecutingAssembly().GetCustomAttributes(false))
{
AssemblyTitleAttribute aTitle=attr as
AssemblyTitleAttribute;
if (aTitle != null)
{
return aTitle.Title;
}
}
return "";
}
You can use the 'is' keyword to also determine if one of the attributes
is the particular attribute for which you are searching.
Regards,
Joe
Harry J. Smith said:
The following set of attributes is always included in file AssemblyInfo.cs:
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.*")]
How can I access their values in my program?
-Harry