首页 > 代码库 > 绑定程序集

绑定程序集

需要配置配置文件

 

1,codeBase:只可用于共享程序集

①:从网络加载

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  
  
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
      <dependentAssembly>  
        <assemblyIdentity name="Timber.Assembly" version="1.0.0.0" publicKeyToken="ad83e08169849671"/>
      <codeBase version="1.0.0.0" href="http://192.188.1.106:8089/dll/Timber.Assembly.dll" />
      </dependentAssembly>  
  </assemblyBinding> 
</runtime>
</configuration>

 

②:指定文件的路径

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  
  
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
      <dependentAssembly>  
        <assemblyIdentity name="Timber.Assembly" version="1.0.0.0" publicKeyToken="ad83e08169849671"/>
      <codeBase version="1.0.0.0" href="file://C:\Users\Administrator\Desktop\Timber.Assembly\Timber.Assembly\bin\Debug\Timber.Assembly.dll" />
      </dependentAssembly>  
  </assemblyBinding> 
</runtime>
</configuration>

publicKeyToken:该程序集的公钥

可以通过sn -T Timber.Assembly.dll 查看公钥

 

 

=====================测试:

Assembly a = Assembly.Load("Timber.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ad83e08169849671");
            Console.WriteLine(a.FullName);
            Console.ReadKey();

 

 

2,probing:可用于共享和私有程序集

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  <runtime>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="zhangdi;bin"></probing>
    </assemblyBinding>
  </runtime>
</configuration>

 privatePath:指定检索程序集的路径

 

 =====================测试:

 Assembly a = Assembly.Load("ClassLibrary1, Version=1.0.0.0");
 Console.WriteLine(a.FullName);
 Console.ReadKey();

本文出自 “程序猿的家--Hunter” 博客,请务必保留此出处http://962410314.blog.51cto.com/7563109/1589850

绑定程序集