Getting a file version

  • Thread starter Thread starter Sharon
  • Start date Start date
Like when you use the windows explorer and right click on a DLL file and
choose Properties, then you can see the Version tab that contains the version
of the file.
I want to read this vfile ersion and compare it with another file to
determine whether to overwrite the existing file in the installer class I'm
using for my VS2005 setup project.
 
The FileVersionInfo.GetVersionInfo should work (-:

But the FileVersionInfo have on the Equals() that returns Boolean value, I
need to one file version with another file to determine which one is the
newer version and by that to determine whether to overwrite the existing
file in the installer class I'm
using for my VS2005 setup project.

How can I determine which file has the newer version?
 
The FileVersionInfo.GetVersionInfo should work (-:

But the FileVersionInfo have on the Equals() that returns Boolean value, I
need to one file version with another file to determine which one is the
newer version and by that to determine whether to overwrite the existing
file in the installer class I'm
using for my VS2005 setup project.

How can I determine which file has the newer version?

FileVersionInfo myFileVersionInfo =
FileVersionInfo.GetVersionInfo("foo.dll");
string version = myFileVersionInfo.FileVersion;

-or-

string version =
FileVersionInfo.GetVersionInfo("foo.dll").FileVersion;

Take a look through the .NET library. It help define the properties of
all the classes:
http://msdn2.microsoft.com/en-us/library/system.diagnostics.fileversioninfo.aspx

goodluck,
-tom
-tom
 
Well, the FileVersionInfo.Version is a string, and can actually be pretty
much anything - however, if you are happy that it will generally be a
standard version, then you could try using Version ver = new
Version(fvi.Version) [if you see what I mean]; Version offers all the
comparisons you should need. However, be sure to catch the exception when
FileVersionInfo.Version is "fred"...

Marc
 
Thanks for the help,
There isn't FileVersionInfo.Version, I guess you mean
FileVersionInfo.FileVersion.
The Version looks nice, but by looking at its documentaion, it says
"Represents the version number for a common language runtime assembly".
Can I use it for native files like COM DLL's?
 
There isn't FileVersionInfo.Version, I guess you mean
FileVersionInfo.FileVersion.
No, I was talking about using the Version class to parse the string.

It will work fine as long as the version is strictly numeric - but as
I warned, that isn't necessarily the case for the FileVersion; for
example:

string path = @"C:\WINDOWS\system32\comctl32.dll";
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(path);
Version version = new Version(fvi.ProductVersion);

works fine, but if I try fvi.FileVersion, it might break (since for me
this is "5.82 (xpsp.060825-0040)" which can't be parsed).

So: if your COM dlls use a.b.c.d version numbers, then new
Version(fvi.FileVersion) should work. You can, however, look at
fvi.FileMajorPart and fvi.FileMinorPart.

Marc
 
Great, thanks.
Even for files like "C:\WINDOWS\system32\comctl32.dll" it is working when
using instead of the FileVersion the following:

string path = @"C:\WINDOWS\system32\comctl32.dll";
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(path);
Version version = new Version(fvi.FileMajorPart, fvi.FileMinorPart,
fvi.FileBuildPart, fvi.FilePrivatePart);
 
Back
Top