The assemblyinfo.cs file has the AssemblyVersion attribute, but when I run the following:
Attribute[] y = Assembly.GetExecutingAssembly().GetCustomAttributes();
I get:
System.Runtime.InteropServices.ComVisibleAttribute
System.Runtime.CompilerServices.RuntimeCompatibilityAttribute
System.Runtime.CompilerServices.CompilationRelaxationsAttribute
System.Runtime.InteropServices.GuidAttribute
System.Diagnostics.DebuggableAttribute
System.Reflection.AssemblyTrademarkAttribute
System.Reflection.AssemblyCopyrightAttribute
System.Reflection.AssemblyCompanyAttribute
System.Reflection.AssemblyConfigurationAttribute
System.Reflection.AssemblyFileVersionAttribute
System.Reflection.AssemblyProductAttribute
System.Reflection.AssemblyDescriptionAttribute
and yet I have checked countless times that this attribute is present in my code:
[assembly: AssemblyVersion("5.5.5.5")]
...and if I try to access it directly I get an exception:
Attribute x = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyVersionAttribute)); //exception
I guess I won't be able to use that attribute, but how come .NET isn't reading it?
If you're trying to just get the assembly version, it's pretty straight forward:
Console.WriteLine("The version of the currently executing assembly is: {0}", Assembly.GetExecutingAssembly().GetName().Version);
The property is a type of System.Version, which has Major
, Minor
, Build
, and Revision
properties.
Eg. an assembly of version 1.2.3.4
has:
Major
= 1
Minor
= 2
Build
= 3
Revision
= 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With