<codeBase > 元素<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

为了使运行时使用计算机配置文件或发布服务器策略文件中的 <codeBase > 设置,该文件还必须重定向程序集版本。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. 应用程序配置文件可以具有基本代码设置,而不会重定向程序集版本。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.

如果程序集具有强名称,则基本代码设置可以是本地 intranet 或 Internet 上的任何位置。If the assembly has a strong name, the codebase setting can be anywhere on the local intranet or the Internet. 如果程序集是私有程序集,则 codebase 设置必须是相对于应用程序目录的路径。If the assembly is a private assembly, the codebase setting must be a path relative to the application's directory.

对于没有强名称的程序集,版本会被忽略,并且加载程序在 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