FileVersionInfo 類別

定義

提供磁碟上實體檔案的版本資訊。

public ref class FileVersionInfo sealed
public sealed class FileVersionInfo
type FileVersionInfo = class
Public 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位號碼,如下所示:

GetVersionInfo使用這個類別的 方法來取得FileVersionInfo包含檔案相關信息的 ,然後查看屬性以取得檔案的相關信息。 屬性 FileVersion 提供檔案的版本資訊。 ProductMajorPartProductMinorPartProductBuildPartProductPrivatePartProductVersion 屬性會提供指定檔案所屬產品的版本資訊。 呼叫 ToString 以取得部分屬性清單及其此檔案的值。

這些 FileVersionInfo 屬性是以檔案內建的版本資源資訊為基礎。 版本資源通常內建在二進位檔中,例如 .exe 或 .dll 檔案;文字檔沒有版本資源資訊。

版本資源通常會在 Win32 資源檔或元件屬性中指定。 例如, IsDebug 屬性會 VS_FF_DEBUG 反映檔案 VS_FIXEDFILEINFO 區塊中的旗標值,這個值是從 VERSIONINFO Win32 資源檔中的資源建置而來。 For more information about specifying version resources in a Win32 resource file, see "About Resource Files" and "VERSIONINFO Resource" in the Platform SDK. 如需在 .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 中部分的屬性清單及其值。

適用於

另請參閱