我在物理路径OF中有一个exe文件simpleservice.exe:\ SAMPLE PRODUCT \ Bin ,,我需要获取该exe文件的版本号,你能给出获取版本号所需的代码
答案 0 :(得分:5)
您可以使用
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;
}
答案 1 :(得分:3)
我会使用以下内容来执行此操作:
Assembly.LoadFrom("...").GetName().Version.ToString();
或者我使用FileVersionInfo类。请选择:
FileVersionInfo.GetVersionInfo("...");
答案 2 :(得分:2)
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(@"F:\SAMPLEPRODUCT\Bin\simpleservice.exe");
Console.WriteLine(fvi.FileVersion);
答案 3 :(得分:1)
AssemblyName anm = AssemblyName.GetAssemblyName(
"c:\\winnt\\microsoft.net\\framework\\v1.0.3705\\mscorlib.dll");
// and show its version
Console.WriteLine(anm.Version.ToString());
答案 4 :(得分:1)
AssemblyName.GetAssemblyName(@"F:\SAMPLEPRODUCT\Bin\simpleservice.exe").Version
答案 5 :(得分:1)
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}