DLL Version number
-
How do I find out the version number of a .NET DLL from within that DLL? I tried:
Assembly a = Assembly.GetAssembly(this.GetType()); object[] attrs = a.GetCustomAttributes(typeof(AssemblyVersionAttribute), true); AssemblyVersionAttribute aVersion = (AssemblyVersionAttribute)(attrs[0]);
But GetCustomAttributes returns an empty array -
How do I find out the version number of a .NET DLL from within that DLL? I tried:
Assembly a = Assembly.GetAssembly(this.GetType()); object[] attrs = a.GetCustomAttributes(typeof(AssemblyVersionAttribute), true); AssemblyVersionAttribute aVersion = (AssemblyVersionAttribute)(attrs[0]);
But GetCustomAttributes returns an empty arrayPaleyX wrote: How do I find out the version number of a .NET DLL from within that DLL? The AssemblyVersionAttribute Class[^] isn't a custom attribute. In order to get the version information (usually as a Version[^] object) you have to use the AssemblyName.Version[^] property. And if a method is supposed to retrieve the version of its own assembly you can use Assembly.GetExecutingAssembly()[^] to get the assembly and Assembly.GetName()[^] to get the AssemblyName object.
public string Version()
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}Best regards Dennis