Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Good day!

I have to a check a file before running my tool. The file to be check is in "c:\code\example.dll". This file has a version of 1.0.21.20

The minimum requirement to run my Tool is version 1.0.20.1. So the given file above pass the requirement to run my tool. And the Tool will run. What if the file version above is below the requirement. Example version 1.0.19.1 so the tool will not run.

How to execute that in C# and if the requirement did not pass, I want to display the requirement needed to run my Tool.


looking forward.


yepey!
-novice in C#-
Posted
Comments
jcosep 12-May-11 4:39am    
please clarify your question

The answer based on file version information is incomplete. There is also assembly version.
File version and assembly version can be different. It's the best to build versioning strategy around assembly versions, not file versions.

Please see my recent answer to this question:
Checking file if it is compatible in the system used[^].

—SA
 
Share this answer
 
You can use below code to check that

MSIL
System.Diagnostics.FileVersionInfo fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(@"C:\msdia80.dll");
            //Check Version
            if(fileVersionInfo.FileVersion == "Some Conditition")
 
Share this answer
 
Comments
Eustass Kid 12-May-11 4:32am    
thank you for giving me the above solution. And I will be glad more if you will include the whole code in order to run that code.

Thank you again.
Manish Ranjan Kumar 12-May-11 4:43am    
static class Program
{
///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
var str = "c:\\windows\\explorer.exe";
System.Diagnostics.FileVersionInfo fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(str);
//Check Version
if(fileVersionInfo.FileMajorPart != 5 )
{
return;
}


Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}

Use this peace of code.
jcosep 12-May-11 4:44am    
don't give the code his taking advantage! haha
Eustass Kid 12-May-11 5:00am    
thank you for sharing that man...I'm really thankful. :)
BobJanova 12-May-11 5:42am    
Correct, and also, Version supports comparisons (> and <) so you can do something like
Version testVersion = new Version(1, 0, 20, 1);
if(fileVersion < testVersion){
// fail
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900