有两种方法用来指定程序集的位置:工具
使用 <codeBase> 元素。spa
使用 <probing> 元素。code
还可使用 .NET Framework 配置工具 (Mscorcfg.msc) 来指定程序集位置或者为公共语言运行库指定要探测程序集的位置。xml
只有在计算机配置文件或也重定向程序集版本的发行者策略文件中,才可使用 <codeBase> 元素。在运行库肯定要使用哪一程序集版本时,它应用肯定版本的文件中的基本代码设置。若是未指出基本代码,那么运行库就以一般的方法探测程序集。有关详细信息,请参见运行库如何定位程序集。get
下面的示例说明如何指定程序集的位置。it
<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>io
对于全部具备强名称的程序集,要求 version 属性,但对于不具备强名称的程序集应省略。<codeBase> 元素要求 href 属性。在 <codeBase> 元素中不能指定版本范围。asm
![]() |
---|
若是为不具备强名称的程序集提供基本代码提示,那么该提示必须指向应用程序基或该应用程序基目录的子目录。table |
运行库经过探测的方法来查找没有基本代码的程序集。有关探测的更多信息,请参见运行库如何定位程序集。class
能够在应用程序配置文件中使用 <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 中指定的目录必须是应用程序基目录的子目录。