指定程序集的位置

可以通过两种方法来指定程序集的位置:

还可以使用 .NET Framework 配置工具 (mscorcfg.msc) 指定程序集位置,或指定公共语言运行时用于探测程序集的位置。

使用 <codeBase> 元素

只有在计算机配置文件或也重定向程序集版本的发行者策略文件中,才可以使用 <codeBase> 元素。 当运行时确定要使用的程序集版本时,它将从确定版本的文件应用基本代码设置。 如果未指定任何代码库,则运行时以正常方式探测程序集。 有关详细信息,请参阅运行时如何定位程序集

以下示例演示如何指定程序集的位置。

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

对于所有具有强名称的程序集,版本特性都是必需的,但对于不具有强名称的程序集,应忽略该特性。 <codeBase> 元素需要 href 特性。 在 <codeBase> 元素中不能指定版本范围。

备注

如果要为不具有强名称的程序集提供基本代码提示,则提示必须指向应用程序基或应用程序基目录的子目录。

使用 <probing> 元素

运行时通过探测来查找没有代码库的程序集。 有关探测的详细信息,请参阅运行时如何定位程序集

可以在应用程序配置文件中使用 <probing> 元素,来指定在查找程序集时运行时应搜索的子目录。 以下示例演示如何指定运行时应搜索的目录。

<configuration>  
   <runtime>  
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
         <probing privatePath="bin;bin2\subbin;bin3"/>  
      </assemblyBinding>  
   </runtime>  
</configuration>  

“privatePath”属性包含运行时应在其中搜索程序集的目录。 如果应用程序位于 C:\Program Files\MyApp,则运行时将查找未在 C:\Program Files\MyApp\Bin、C:\Program Files\MyApp\Bin2\Subbin 和 C:\Program Files\MyApp\Bin3 中指定基本代码的程序集。 在 privatePath 中指定的目录必须是应用程序基目录的子目录。

请参阅