FileVersionInfo 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为磁盘上的物理文件提供版本信息。
public ref class FileVersionInfo sealedpublic sealed class FileVersionInfotype FileVersionInfo = classPublic NotInheritable Class FileVersionInfo- 继承
- 
				FileVersionInfo
示例
以下示例调用 GetVersionInfo 以获取 FileVersionInfo 记事本的 。 然后,它将文件说明和版本号打印到控制台。
#using <System.dll>
using namespace System;
using namespace System::IO;
using namespace System::Diagnostics;
public ref class Class1
{
    
public:
    static void Main()
    {
        // Get the file version for the notepad.
        // Use either of the two following methods.
        FileVersionInfo::GetVersionInfo(Path::Combine(Environment::SystemDirectory, "Notepad.exe"));
        FileVersionInfo^ myFileVersionInfo = FileVersionInfo::GetVersionInfo(Environment::SystemDirectory + "\\Notepad.exe");
        // Print the file name and version number.
        Console::WriteLine("File: " + myFileVersionInfo->FileDescription + "\n" +
           "Version number: " + myFileVersionInfo->FileVersion);
    }
};
int main()
{
    Class1::Main();
}
using System;
using System.IO;
using System.Diagnostics;
class Class1
{
    public static void Main(string[] args)
    {
        // Get the file version for the notepad.
        // Use either of the two following commands.
        FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "Notepad.exe"));
        FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\\Notepad.exe");
        // Print the file name and version number.
        Console.WriteLine("File: " + myFileVersionInfo.FileDescription + '\n' +
           "Version number: " + myFileVersionInfo.FileVersion);
    }
}
Imports System.IO
Imports System.Diagnostics
Class Class1
    Public Shared Sub Main(ByVal args() As String)
        ' Get the file version for the notepad.
        ' Use either of the following two commands.
        FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "Notepad.exe"))
        Dim myFileVersionInfo As FileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\Notepad.exe")
        ' Print the file name and version number.
        Console.WriteLine("File: " + myFileVersionInfo.FileDescription + vbLf + "Version number: " + myFileVersionInfo.FileVersion)
    End Sub
End Class
注解
通常,版本号显示为“major number.minor number.build number.private part number”。 文件版本号是保存文件的版本号的 64 位数字,如下所示:
- 前 16 位是 FileMajorPart 数字。 
- 接下来的 16 位是 FileMinorPart 数字。 
- 第三组 16 位是 FileBuildPart 数字。 
- 最后 16 位是 FilePrivatePart 数字。 
GetVersionInfo使用此类的 方法获取FileVersionInfo包含有关文件的信息,然后查看属性以获取有关该文件的信息。 属性 FileVersion 提供有关文件的版本信息。 ProductMajorPart、ProductMinorPart、ProductBuildPart、 ProductPrivatePart和 ProductVersion 属性为指定文件所属的产品提供版本信息。 调用 ToString 以获取此文件的属性及其值的部分列表。
这些 FileVersionInfo 属性基于文件中内置的版本资源信息。 版本资源通常内置于二进制文件中,例如 .exe 或 .dll 文件;文本文件没有版本资源信息。
版本资源通常在 Win32 资源文件或程序集属性中指定。 例如, IsDebug 属性反映 VS_FF_DEBUG 文件的 VS_FIXEDFILEINFO 块中的标志值,该块是从 VERSIONINFO Win32 资源文件中的资源生成的。  有关在 Win32 资源文件中指定版本资源的详细信息,请参阅平台 SDK 中的“关于资源文件”和“VERSIONINFO 资源”。 有关在 .NET 模块中指定版本资源的详细信息,请参阅 设置程序集属性 主题。
注意
此类在类级别提出适用于所有成员的链接需求。 SecurityException当直接调用方没有完全信任权限时,将引发 。 有关链接需求的详细信息,请参阅 链接需求。
属性
| Comments | 获取与文件关联的注释。 | 
| CompanyName | 获取生成此文件的公司的名称。 | 
| FileBuildPart | 获取文件的生成号。 | 
| FileDescription | 获取文件说明。 | 
| FileMajorPart | 获取版本号的主要版本号部分。 | 
| FileMinorPart | 获取文件版本号的次要部分。 | 
| FileName | 获取 FileVersionInfo 的此实例所描述的文件的名称。 | 
| FilePrivatePart | 获取文件专用部件号。 | 
| FileVersion | 获取文件版本号。 | 
| InternalName | 获取文件的内部名称(如果存在)。 | 
| IsDebug | 获取一个值,该值指定文件是否包含调试信息或在调试功能启用的情况下进行编译。 | 
| IsPatched | 获取一个值,该值指定该文件是否已修改,且不同于相同版本号的原始发行文件。 | 
| IsPreRelease | 获取一个值,该值指定该文件是否为开发版本,而不是用于商业目的的发行版。 | 
| IsPrivateBuild | 获取一个值,该值指定文件是否采用标准的发行过程生成。 | 
| IsSpecialBuild | 获取一个值,该值指定该文件是否为特殊内部版本。 | 
| Language | 获取版本信息区的默认语言字符串。 | 
| LegalCopyright | 获取所有适用于指定文件的版权声明。 | 
| LegalTrademarks | 获取应用到文件的商标和注册商标。 | 
| OriginalFilename | 获取创建文件时所使用的名称。 | 
| PrivateBuild | 获取文件私有版本的信息。 | 
| ProductBuildPart | 获取该文件关联产品的生成号。 | 
| ProductMajorPart | 获取与此文件关联的产品版本号的主要部分。 | 
| ProductMinorPart | 获取文件关联产品版本号的次要部分。 | 
| ProductName | 获取与此文件一起发行的产品的名称。 | 
| ProductPrivatePart | 获取此文件关联产品的专用部件号。 | 
| ProductVersion | 获取与此文件一起发行的产品的版本。 | 
| SpecialBuild | 获取文件的特殊内部版本信息。 | 
方法
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| GetVersionInfo(String) | 返回表示与指定文件关联的版本信息的 FileVersionInfo。 | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回 FileVersionInfo 中属性及相应值的部分列表。 |