Wednesday, October 8, 2008

WPF: Getting at information entered in Assembly Information dialog

Had a perplexing problem with Getting at information entered in Assembly Information dialog in a WPF application, and it was very quickly answered by Krisha Barghav on the MSDN forums:

WPF: Getting at information entered in Assembly Information dialog

anything you enter inside Assemblyinformation dialog sits in the AssemblyInfo.cs

You can access these values using Assembly.GetExecutingAssembly.GetCustomAttributes(true/false);

If you print the types of attributes returned, you can see something like shown below.

System.Windows.ThemeInfoAttribute
System.Diagnostics.DebuggableAttribute
System.Runtime.CompilerServices.CompilationRelaxationsAttribute
System.Runtime.InteropServices.ComVisibleAttribute
System.Reflection.AssemblyFileVersionAttribute
System.Runtime.CompilerServices.RuntimeCompatibilityAttribute
System.Reflection.AssemblyTitleAttribute
System.Reflection.AssemblyDescriptionAttribute
System.Reflection.AssemblyConfigurationAttribute
System.Reflection.AssemblyCompanyAttribute
System.Reflection.AssemblyProductAttribute
System.Reflection.AssemblyCopyrightAttribute
System.Reflection.AssemblyTrademarkAttribute


So if you want to access the Description entered in the Assembly, you can do something like this.


foreach (object o in Assembly.GetExecutingAssembly().GetCustomAttributes(true))
{
if (o is AssemblyDescriptionAttribute) Debug.WriteLine((o as AssemblyDescriptionAttribute).Description);
}

That is just an example.

Hope this helps.


Worked great for me!

No comments: