You can specify your complete version structure using the assembly-level attribute
System.Reflection.AssemblyVersionAttribute
, please see:
http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.aspx[
^].
Usually you have this attribute auto-generated when you create any project from template in your file "AssemblyInfo.cs". Here is how it looks:
using System.Reflection;
[assembly: AssemblyVersion("1.32.12.11")]
You extract this structure using Reflection from any assembly. If you need an assembly of your application, you usually need an entry assembly, the one loaded first, having an entry point and referencing all other assemblies and executable module. To get it, use
System.Reflection.Assembly.GetEntryAssembly()
, but you can get this version information from any assembly you need. Please see:
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx[
^].
In your code, you need to get the version attribute using
System.Reflection.Assembly.GetCustomAttributes(System.Type, bool)
, please see:
http://msdn.microsoft.com/en-us/library/88d17d13.aspx[
^].
For example:
System.Reflection.AssemblyVersionAttribute GetAssemblyVersion(System.Reflection.Assembly assembly) {
object[] attributes = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyVersionAttribute), false);
if (attribute == null) return null;
if (attrubutes.Length < 1) return null;
System.Reflection.AssemblyVersionAttribute attrubute = (System.Reflection.AssemblyVersionAttribute)attributes[0];
return new System.Reflection.AssemblyVersionAttribute(attribute.Version);
}
If this method returns null, it indicated that the assembly is not given a version. If this is not null, use the value in your display or elsewhere.
—SA