How to retrieve AssemblyInfo in C#

How to retrieve AssemblyInfo in C#

 

Posted by: Rickie / June. 29, 2006

The following code snippet shows you how to programmatically retrieve information from AssemblyInfo.cs, e.g. AssemblyProduct, AssemblyVersion, AssemblyCopyright.

 

Take the following AssemblyInfo.cs as an example:

[assembly: AssemblyTitle("Enjoy coding experience")]

[assembly: AssemblyDescription("")]

[assembly: AssemblyConfiguration("")]

[assembly: AssemblyCompany("http://rickie.cnblogs.com/")]

[assembly: AssemblyProduct("your proudct name")]

[assembly: AssemblyCopyright("Copyright © Rickie 2006")]

[assembly: AssemblyTrademark("")]

[assembly: AssemblyCulture("")]

 

The code snippet in C# is used to retrieve the above information in AssemblyInfo.cs.

 

Assembly a = Assembly.GetExecutingAssembly();

txtVersion.Text = a.GetName().Version.ToString();

 

object[] attrib = a.GetCustomAttributes(typeof(AssemblyProductAttribute), false);

lblTitle.Text = ((AssemblyProductAttribute)attrib[0]).Product;

attrib = a.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);

lblCopyright.Text = ((AssemblyCopyrightAttribute)attrib[0]).Copyright;

attrib = a.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);

lblTitleCN.Text = ((AssemblyTitleAttribute)attrib[0]).Title;

 

 

posted @ 2006-06-29 13:47  Rickie  阅读(1180)  评论(2编辑  收藏  举报