"Matthew Smith" <ma*****@macxxx .com> wrote in message news:ma******** *************** ****@msnews.mic rosoft.com...
Is there a way to get the value that is stored in the AssemblyVersion
attribute that's in AssemblyInfo.cs ?
Yes, you can get a reference to the currently executing assembly and
then get it's custom attributes (filtering by type: AssemblyVersion Attribute)
like this,
using System.Reflecti on;
// . . .
Assembly assy = Assembly.GetExe cutingAssembly( );
AssemblyVersion Attribute[] versionAttrs = (AssemblyVersio nAttribute[ ])
assy.GetCustomA ttributes( typeof( AssemblyVersion Attribute), false);
if ( versionAttrs != null && 0 < versionAttrs.Le ngth ) {
Console.WriteLi ne( "Assembly version is {0}.", versionAttrs[ i].Version);
}
GetCustomAttrib utes( ) works for any Attribute but it returns an array of
plain object references, so don't forget to typecast it to the appropriate
Type of Attribute. If you pass the Type as the argument then you can be
guaranteed that the typecast is valid.
Derek Harmon