Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Version number of a dll in .NET

Tags:

Given the following:

string file = @"c:\somepath\somefile.dll"; 

How can I find the file and product version numbers of that DLL using .NET?

The dll can be either native or managed.

Thanks.

like image 390
rein Avatar asked Oct 08 '09 13:10

rein


2 Answers

Yes, using System.Diagnostics.FileVersionInfo.

string fileVersion = FileVersionInfo.GetVersionInfo(file).FileVersion; string productVersion = FileVersionInfo.GetVersionInfo(file).ProductVersion; 

Be advised that the file version of an assembly could be different from its assembly version. The assembly version is part of the assembly's identity.

like image 86
Lars Truijens Avatar answered Sep 24 '22 10:09

Lars Truijens


I don't know about native dlls but with managed dlls it works like this:

System.Reflection.Assembly.LoadFile(file).GetName().Version 

EDIT: I think you can read the version info in C with GetFileVersionInfo()...

like image 27
EricSchaefer Avatar answered Sep 23 '22 10:09

EricSchaefer