我正在尝试从 EXE 文件中读取“文件版本”和“产品版本”文件属性。
我正在尝试使用该FileVersionInfo.GetVersionInfo().FileVersion
函数,但它没有返回完整的“文件版本”属性(例如,实际文件版本是“1.6.0.7”---->,该FileVersionInfo
函数返回“1.6”)
当我在我的 PC 上安装 Windows 7 时,我正在使用以下运行良好的代码。
Shell shell = new Shell();
Folder objFolder = shell.NameSpace(Path.GetDirectoryName(strFileName));
FolderItem folderItem = objFolder.ParseName(Path.GetFileName(strFileName));
string fileversion = objFolder.GetDetailsOf(folderItem, 156)
在 Windows 10 上,上述代码根本不起作用。
更新 #1 - 根据要求,完整代码是:
string fileversion = FileVersionInfo.GetVersionInfo(@"E:\NewFolder\file.exe").FileVersion;
[程序集:AssemblyFileVersion("1.0.0.0")]
更新 #2 - 以下代码确实正确返回了完整版本
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo("C:\\MyFile.txt");
int major = fvi.ProductMajorPart;
int minor = fvi.ProductMinorPart;
int build = fvi.ProductBuildPart;
int revsn = fvi.ProductPrivatePart;
string q = String.Concat(major.ToString(), ".", minor.ToString(), ".", build.ToString(), ".", revsn.ToString());