问题
I have an exe file simpleservice.exe in the physical path F:\SAMPLEPRODUCT\Bin ,, i need to fetch version number of that exe file,,Can you give the code required to fetch the version number
回答1:
I'd use the following to do this:
Assembly.LoadFrom("...").GetName().Version.ToString();
or I'd use the FileVersionInfo class. Take your pick:
FileVersionInfo.GetVersionInfo("...");
回答2:
You can use
FileVersionInfo.GetVersionInfo
for this
Eg:
public void GetFileVersion() {
// Get the file version for the exe.
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo("your_exe_file");
// Print the file name and version number.
textBox1.Text = "File: " + myFileVersionInfo.FileDescription + '\n' +
"Version number: " + myFileVersionInfo.FileVersion;
}
回答3:
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(@"F:\SAMPLEPRODUCT\Bin\simpleservice.exe");
Console.WriteLine(fvi.FileVersion);
回答4:
AssemblyName anm = AssemblyName.GetAssemblyName(
"c:\\winnt\\microsoft.net\\framework\\v1.0.3705\\mscorlib.dll");
// and show its version
Console.WriteLine(anm.Version.ToString());
回答5:
AssemblyName.GetAssemblyName(@"F:\SAMPLEPRODUCT\Bin\simpleservice.exe").Version
回答6:
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
来源:https://stackoverflow.com/questions/1388178/information-from-exe-file