<dependency> 元素 (ClickOnce 應用程式)

識別應用程式所需的平台或組件相依性。

語法


      <dependency>
   <dependentOS
      supportURL
      description
   >
      <osVersionInfo>
         <os
            majorVersion
            minorVersion
            buildNumber
            servicePackMajor
            servicePackMinor
            productType
            suiteType
         />
      </osVersionInfo>
   </dependentOS>
   <dependentAssembly
      dependencyType
      allowDelayedBinding
      group
      codeBase
      size
   >
      <assemblyIdentity
         name
         version
         processorArchitecture
         language
      >
         <hash>
            <dsig:Transforms>
               <dsig:Transform
                  Algorithm
            />
            </dsig:Transforms>
            <dsig:DigestMethod />
            <dsig:DigestValue>
            </dsig:DigestValue>
    </hash>

      </assemblyIdentity>
   </dependentAssembly>
</dependency>

元素和屬性

dependency 元素為必要項。 在同一個應用程式資訊清單中可能存在多個 dependency 執行個體。

dependency 元素沒有屬性,並且包含以下子項目。

dependentOS

選擇性。 包含 osVersionInfo 元素。 dependentOSdependentAssembly 元素是互斥的:兩者中的一個必須為 dependency 元素存在,但不能同時存在。

dependentOS 支援以下屬性。

屬性 描述
supportUrl 選擇性。 指定相依平台的支援 URL。 如果找到所需平台,則會向使用者顯示此 URL。
description 選擇性。 以人類可讀的形式描述 dependentOS 元素所描述的作業系統。

osVersionInfo

必要。 這個元素是 dependentOS 元素的子項,並包含 os 元素。 這個元素沒有屬性。

os

必要。 這個元素是 osVersionInfo 元素的子項。 這個項目具有下列屬性。

屬性 描述
majorVersion 必要。 指定作業系統的主要版本號碼。
minorVersion 必要。 指定作業系統的次要版本號碼。
buildNumber 必要。 指定作業系統的組建編號。
servicePackMajor 必要。 指定作業系統的 Service Pack 主要號碼。
servicePackMinor 選擇性。 指定作業系統的 Service Pack 次要號碼。
productType 選擇性。 識別產品類型值。 有效值為 serverworkstationdomainController。 例如,針對 Windows 10,這個屬性值為 workstation
suiteType 選擇性。 識別系統上可用的產品套件或系統的設定類型。 有效值為 backofficebladedatacenterenterprisehomeprofessionalsmallbusinesssmallbusinessRestrictedterminal。 例如,對於 Windows 2000 Professional,此屬性值為 professional

dependentAssembly

選擇性。 包含 assemblyIdentity 元素。 dependentOSdependentAssembly 元素是互斥的:兩者中的一個必須為 dependency 元素存在,但不能同時存在。

dependentAssembly 具有下列屬性。

屬性 描述
dependencyType 必要。 指定相依性類型。 有效值為 prerequisiteinstallinstall 組件是作為 ClickOnce 應用程式的一部分安裝的。 在安裝 ClickOnce 應用程式之前,全域組件快取 (GAC) 中必須存在 prerequisite 組件。
allowDelayedBinding 必要。 指定是否可以在執行階段以程式設計方式載入組件。
group 選擇性。 如果 dependencyType 屬性設定為 install,則指定一組僅視需要安裝的具名屬性。 如需詳細資訊,請參閱逐步解說:下載組件隨選與 ClickOnce 部署應用程式開發介面使用設計工具

如果設定為 framework 並且 dependencyType 屬性設定為 prerequisite,則將組件指定為 .NET Framework 的一部分。 在 .NET Framework 4 和更新版本上安裝時,不會檢查此元件的全域程式集緩存 (GAC)。
codeBase dependencyType 屬性設定為 install 時需要。 相依組件的路徑。 可以是絕對路徑,也可以是相對於資訊清單之程式碼基底的路徑。 此路徑必須是有效 URI,資訊清單才能有效。
size dependencyType 屬性設定為 install 時需要。 相依組件的大小,以位元組為單位。

assemblyIdentity

必要。 這個元素是 dependentAssembly 元素的子項,並具有下列屬性。

屬性 描述
name 必要。 識別應用程式的名稱。
version 必要。 依以下格式指定應用程式的版本號碼:major.minor.build.revision
publicKeyToken 選擇性。 指定 16 個字元的十六進位字串,其表示用於對應用程式或組件進行簽署之公開金鑰的 SHA-1 雜湊值的最後 8 個位元組。 用於對目錄進行簽署的公開金鑰必須不小於 2048 位元。
processorArchitecture 選擇性。 指定處理器。 對於 32 位元 Windows,有效值為 x86,對於 64 位元 Windows,則為 I64
language 選擇性。 識別組件的兩部分語言程式碼,如 EN-US。

雜湊

hash 元素是 assemblyIdentity 元素的選用子系。 hash 項目沒有任何屬性。

ClickOnce 會使用應用程式中所有檔案的演算法雜湊作為安全性檢查,以確保部署後沒有任何檔案變更。 如果未包含 hash 元素,將不會執行此檢查。 因此,不建議省略 hash 元素。

dsig:Transforms

dsig:Transforms 元素是 hash 元素的必要子系。 dsig:Transforms 項目沒有任何屬性。

dsig:Transform

dsig:Transform 元素是 dsig:Transforms 元素的必要子系。 dsig:Transform 項目具有下列屬性。

屬性 描述
Algorithm 用來計算此檔案摘要的演算法。 目前 ClickOnce 使用的唯一值是 urn:schemas-microsoft-com:HashTransforms.Identity

dsig:DigestMethod

dsig:DigestMethod 元素是 hash 元素的必要子系。 dsig:DigestMethod 項目具有下列屬性。

屬性 描述
Algorithm 用來計算此檔案摘要的演算法。 目前 ClickOnce 使用的唯一值是 http://www.w3.org/2000/09/xmldsig#sha1

dsig:DigestValue

dsig:DigestValue 元素是 hash 元素的必要子系。 dsig:DigestValue 項目沒有任何屬性。 其文字值是指定檔案的計算雜湊。

備註

應用程式使用的所有組件都必須具有相應的 dependency 元素。 相依組件不包括必須作為平台組件預先安裝在全域組件快取中的組件。

範例

下方的程式碼範例示範了 ClickOnce 應用程式清單中的 dependency 個元素。 此程式碼範例是針對 ClickOnce 應用程式資訊清單主題提供的較大範例的一部分。

<dependency>
  <dependentOS>
    <osVersionInfo>
      <os
        majorVersion="4"
        minorVersion="10"
        buildNumber="0"
        servicePackMajor="0" />
    </osVersionInfo>
  </dependentOS>
</dependency>
<dependency>
  <dependentAssembly
    dependencyType="preRequisite"
    allowDelayedBinding="true">
    <assemblyIdentity
      name="Microsoft.Windows.CommonLanguageRuntime"
      version="4.0.20506.0" />
  </dependentAssembly>
</dependency>

<dependency>
  <dependentAssembly
    dependencyType="install"
    allowDelayedBinding="true"
    codebase="MyApplication.exe"
    size="4096">
    <assemblyIdentity
      name="MyApplication"
      version="1.0.0.0"
      language="neutral"
      processorArchitecture="x86" />
    <hash>
      <dsig:Transforms>
        <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
      </dsig:Transforms>
      <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
      <dsig:DigestValue>DpTW7RzS9IeT/RBSLj54vfTEzNg=</dsig:DigestValue>
    </hash>
  </dependentAssembly>
</dependency>

另請參閱