C# 获取exe文件的版本信息

    /// <summary>
    /// 获取exe的版本信息
    /// </summary>
    /// <param name="filePath"></param>
    /// <returns></returns>
    public static string GetExeVersion(string filePath)
    {
        // 检查文件路径是否有效
        if (!File.Exists(filePath))
        {
            //throw new FileNotFoundException("指定的文件未找到。", filePath);
            return "";
        }

        // 获取文件的版本信息
        FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(filePath);
        if (versionInfo != null)
        {
            // 返回文件的版本号
            return versionInfo.FileVersion;
        }
        else
        {
            return "";
        }
    }
posted @ 2024-09-11 11:11  boker_gan  阅读(211)  评论(0)    收藏  举报