<b a s e > 元素<codeBase> Element

指定公共语言运行时在哪里可以找到程序集。Specifies where the common language runtime can find an assembly.

<configuration> <runtime> <assemblyBinding> <dependentAssembly> <codeBase><configuration> <runtime> <assemblyBinding> <dependentAssembly> <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. 程序集版本号的格式major.minor.build.revisionThe format of an assembly version number is major.minor.build.revision.

版本属性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

运行时要使用 <b a s e > 设置计算机配置文件或发布服务器策略文件中,该文件还必须重定向程序集版本。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. 如果程序集私有程序集,基本代码设置必须为应用程序的目录的相对路径。If the assembly is a private assembly, the codebase setting must be a path relative to the application's directory.

对于没有强名称程序集,则忽略版本和加载程序将使用出现的第一个<o d e b > 内<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