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;

 

 

相关文章:

  • 2021-12-23
  • 2021-12-26
  • 2021-04-19
  • 2021-08-18
  • 2021-07-18
  • 2021-08-29
  • 2021-05-26
  • 2021-08-27
猜你喜欢
  • 2021-07-02
  • 2021-11-27
  • 2021-11-11
  • 2021-12-12
  • 2021-11-26
  • 2022-01-12
  • 2021-12-14
  • 2021-09-14
相关资源
相似解决方案