I came across a scenario where I had to access some information from a file with .dll extension. And then I thought to write this post. This information may include that assembly’s product name, product version, file version etc.
This scenario may be required either to read a .dll file from disk or from the current running application. The code below covers both the scenarios:
1234567891011
// From executing application.
string assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
// From a physical file, provide full path to that file.
string assemblyVersion = Assembly.LoadFile('your assembly file').GetName().Version.ToString();
// From executing application, gives file version.
string fileVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
// From executing application, gives product version.
string productVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;