【发布时间】:2009-09-07 08:23:12
【问题描述】:
我在物理路径 F:\SAMPLEPRODUCT\Bin 中有一个 exe 文件 simpleservice.exe,我需要获取该 exe 文件的版本号,你能给出获取版本号所需的代码
【问题讨论】:
-
simpleservice.exe是用什么语言写的?
-
或者如果你只是想在资源管理器中看到它?然后右键单击并转到属性|详情。
我在物理路径 F:\SAMPLEPRODUCT\Bin 中有一个 exe 文件 simpleservice.exe,我需要获取该 exe 文件的版本号,你能给出获取版本号所需的代码
【问题讨论】:
你可以使用
FileVersionInfo.GetVersionInfo
为此
例如:
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;
}
【讨论】:
我会使用以下方法来做到这一点:
Assembly.LoadFrom("...").GetName().Version.ToString();
或者我会使用 FileVersionInfo 类。任君挑选:
FileVersionInfo.GetVersionInfo("...");
【讨论】:
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(@"F:\SAMPLEPRODUCT\Bin\simpleservice.exe");
Console.WriteLine(fvi.FileVersion);
【讨论】:
AssemblyName anm = AssemblyName.GetAssemblyName(
"c:\\winnt\\microsoft.net\\framework\\v1.0.3705\\mscorlib.dll");
// and show its version
Console.WriteLine(anm.Version.ToString());
【讨论】:
AssemblyName.GetAssemblyName(@"F:\SAMPLEPRODUCT\Bin\simpleservice.exe").Version
【讨论】:
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
【讨论】: