Share via


設定組件屬性

更新:2007 年 11 月

組件屬性值會提供關於組件的資訊。組件屬性可區分成下列資訊組合:

  • 組件識別屬性

  • 資訊屬性

  • 組件資訊清單屬性

  • 強式名稱屬性

組件識別屬性

三種屬性加上強式名稱 (如果有的話) 共同決定組件的識別:名稱、版本和文化特性。這些屬性將形成組件的完整名稱,而且是在程式碼中參考組件時必須使用的屬性。您可以使用屬性來設定組件的版本和文化特性。編譯器或組件連結器 (Al.exe) 可在建立組件時,根據含有組件資訊清單的檔案來設定名稱值。

下表將說明版本和文化特性屬性。

組件識別屬性

說明

AssemblyCultureAttribute

列舉欄位,指出組件支援的文化特性。組件也可指定文化特性的獨立性,指出組件包含預設文化特性資源。

注意事項:

執行階段將所有未將文化特性屬性設為 null 的組件視為附屬組件。此類組件受致於附屬組件繫結規則 (Rule)。如需詳細資訊,請參閱執行階段如何找出組件

AssemblyFlagsAttribute

設定組件屬性的值,例如是否可並存執行組件。

AssemblyVersionAttribute

格式為 major.minor.build.revision 的數值 (例如 2.4.0.0)。Common Language Runtime 會使用這個值在強式名稱的組件中執行繫結作業。

注意事項:

如果 AssemblyInformationalVersionAttribute 屬性 (Attribute) 未套用至組件,則 AssemblyVersionAttribute 屬性 (Attribute) 指定的版本號碼會由 Application.ProductVersionApplication.UserAppDataPathApplication.UserAppDataRegistry 屬性 (Property) 所使用。

下列程式碼範例說明如何套用版本和文化特性屬性到組件。

'Set version number for the assembly.
<Assembly:AssemblyVersionAttribute("4.3.2.1")>
'Set culture as German.
<Assembly:AssemblyCultureAttribute("de")>
//Set version number for the assembly.
[assembly:AssemblyVersionAttribute("4.3.2.1")]
//Set culture as German.
[assembly:AssemblyCultureAttribute("de")]

資訊屬性

您可以使用資訊屬性來提供組件的其他公司或產品資訊。下表說明可套用到組件的資訊屬性。

資訊屬性

說明

AssemblyCompanyAttribute

字串值,可指定公司名稱。

AssemblyCopyrightAttribute

字串值,可指定著作權資訊。

AssemblyFileVersionAttribute

字串值,可指定 Win32 檔案版本編號。該字串值的預設值為組件版本。

AssemblyInformationalVersionAttribute

字串值,可指定 Common Language Runtime 未使用的版本資訊,例如完整的產品版本號碼。

注意事項:

如果此屬性 (Attribute) 套用至組件,則可以在執行階段使用 Application.ProductVersion 屬性 (Property) 取得所指定的字串。此字串也可用於 Application.UserAppDataPathApplication.UserAppDataRegistry 屬性提供的路徑和登錄機碼。

AssemblyProductAttribute

字串值,可指定產品資訊。

AssemblyTrademarkAttribute

字串值,可指定商標資訊。

這些屬性會出現在組件的 Windows 屬性頁,或使用 /win32res 編譯器選項來指定您的 Win32 資源檔,以覆寫這些屬性值。

組件資訊清單屬性

您可以使用組件資訊清單屬性提供組件資訊清單中的資訊,包括標題、說明、預設別名和組態。下表即說明組件資訊清單屬性。

組件資訊清單屬性

說明

AssemblyConfigurationAttribute

字串值,指出組件的組態,例如組件是正式版或偵錯版。執行階段並不會使用這個值。

AssemblyDefaultAliasAttribute

字串值,指定參考組件時使用的預設別名。如果組件的名稱不容易記住 (例如 GUID 值),該值將提供易記名稱。該值也可做為完整組件名稱的簡短形式。

AssemblyDescriptionAttribute

字串值,可指定用來摘要說明組件的性質和作用的簡短說明。

AssemblyTitleAttribute

字串值,可指定組件的易記名稱。例如,comdlg 組件可使用 Microsoft Common Dialog Control 標題。

強式名稱屬性

您可以使用強式名稱屬性來設定組件強式名稱。下表說明強式名稱屬性。

強式名稱屬性

說明

AssemblyDelaySignAttribute

布林值,指示目前正使用延遲簽名。

AssemblyKeyFileAttribute

字串值,指示含有公開金鑰 (如果是使用延遲簽名) 或同時含有公用和私秘金鑰的檔名,被當做引數傳遞給這個屬性的建構函式。請注意,檔名相對於輸出檔案路徑 (.exe 或 .dll),而非原始程式檔路徑。

AssemblyKeyNameAttribute

指出含有金鑰組的金鑰容器被當做引數傳遞給這個屬性的建構函式。

下列程式碼範例說明使用延遲簽名來建立使用 myKey.snk 公開金鑰檔的強式名稱組件時,所套用的屬性。

      <Assembly:AssemblyKeyFileAttribute("myKey.snk")>
      <Assembly:AssemblyDelaySignAttribute(True)>
      [assembly:AssemblyKeyFileAttribute(@"..\..\myKey.snk")]
      [assembly:AssemblyDelaySignAttribute(true)]

請參閱

概念

建立組件

其他資源

使用組件設計程式