<程式碼基底 > 元素<codeBase> Element

指定通用語言執行時間可以找到元件的位置。Specifies where the common language runtime can find an assembly.

<configuration> <configuration>
   <執行時間 >   <runtime>
     <assemblyBinding >     <assemblyBinding>
       <dependentAssembly >       <dependentAssembly>
         <codeBase>        <codeBase>

語法Syntax

   <codeBase
        version="Assembly version"
        href="URL of assembly"/>

屬性和項目Attributes and Elements

下列各節描述屬性、子項目和父項目。The following sections describe attributes, child elements, and parent elements.

屬性Attributes

屬性Attribute 描述Description
href 必要屬性。Required attribute.

指定執行時間可以找到元件之指定版本的 URL。Specifies the URL where the runtime can find the specified version of the assembly.
version 必要屬性。Required attribute.

指定程式碼基底適用的元件版本。Specifies the version of the assembly the codebase applies to. 元件版本號碼的格式為 [主要. 次要. 組建. 修訂]。The format of an assembly version number is major.minor.build.revision.

version 屬性version Attribute

Value 說明Description
版本號碼的每個部分的有效值為0到65535。Valid values for each part of the version number are 0 to 65535. 不適用。Not applicable.

子元素Child Elements

無。None.

父項目Parent Elements

項目Element 描述Description
buildproviders 定義用來編譯自訂資源檔的組建提供者集合。Defines a collection of build providers used to compile custom resource files. 組建提供者的數量不限。You can have any number of build providers.
compilation 設定 ASP.NET 使用的所有編譯設定。Configures all the compilation settings that ASP.NET uses.
configuration 通用語言執行平台和 .NET Framework 應用程式所使用之每個組態檔中的根項目。The root element in every configuration file used by the common language runtime and .NET Framework applications.
System.web 指定 ASP.NET 組態區段的根項目。Specifies the root element for the ASP.NET configuration section.

備註Remarks

若要使用執行階段 <程式碼基底> 設定在電腦組態檔或發行者原則檔中,檔案也必須重新導向組件版本。For the runtime to use the <codeBase> setting in a machine configuration file or publisher policy file, the file must also redirect the assembly version. 應用程式佈建檔可以有 codebase 設定,而不需要重新導向元件版本。Application configuration files can have a codebase setting without redirecting the assembly version. 決定要使用哪個元件版本之後,執行時間會從判斷版本的檔案套用程式碼基底設定。After determining which assembly version to use, the runtime applies the codebase setting from the file that determines the version. 如果未指出程式碼基底,則執行時間會以一般方式探查元件。If no codebase is indicated, the runtime probes for the assembly in the usual way.

如果元件具有強式名稱,則程式碼基底設定可以是近端內部網路或網際網路上的任何位置。If the assembly has a strong name, the codebase setting can be anywhere on the local intranet or the Internet. 如果元件是私用元件,則程式碼基底設定必須是相對於應用程式目錄的路徑。If the assembly is a private assembly, the codebase setting must be a path relative to the application's directory.

針對沒有強式名稱的元件,會忽略 version,而載入器會在 dependentAssembly > <內<使用程式碼基底的第一個外觀 >。For assemblies without a strong name, version is ignored and the loader uses the first appearance of <codebase> inside <dependentAssembly>. 如果應用程式佈建檔中有一個專案會將系結重新導向至另一個元件,則即使元件版本不符合系結要求,重新導向也會優先。If there is an entry in the application configuration file that redirects binding to another assembly, the redirection will take precedence even if the assembly version doesn't match the binding request.

範例Example

下列範例顯示如何指定執行時間可以找到元件的位置。The following example shows how to specify where the runtime can find an assembly.

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="myAssembly"
                              publicKeyToken="32ab4ba45e0a69a1"
                              culture="neutral" />
            <codeBase version="2.0.0.0"
                      href="http://www.litwareinc.com/myAssembly.dll"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

另請參閱See also