绑定程序集
需要配置配置文件
1,codeBase:只可用于共享程序集
①:从网络加载
<?xmlversion="1.0"encoding="utf-8"?><configuration><startup><supportedRuntimeversion="v4.0"sku=".NETFramework,Version=v4.5"/></startup><runtime><assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentityname="Timber.Assembly"version="1.0.0.0"publicKeyToken="ad83e08169849671"/><codeBaseversion="1.0.0.0"href="http://192.188.1.106:8089/dll/Timber.Assembly.dll"/></dependentAssembly></assemblyBinding></runtime></configuration>
②:指定文件的路径
<?xmlversion="1.0"encoding="utf-8"?><configuration><startup><supportedRuntimeversion="v4.0"sku=".NETFramework,Version=v4.5"/></startup><runtime><assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentityname="Timber.Assembly"version="1.0.0.0"publicKeyToken="ad83e08169849671"/><codeBaseversion="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 查看公钥
=====================测试:
Assemblya=Assembly.Load("Timber.Assembly,Version=1.0.0.0,Culture=neutral,PublicKeyToken=ad83e08169849671");Console.WriteLine(a.FullName);Console.ReadKey();
2,probing:可用于共享和私有程序集
<?xmlversion="1.0"encoding="utf-8"?><configuration><startup><supportedRuntimeversion="v4.0"sku=".NETFramework,Version=v4.5"/></startup><runtime><assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1"><probingprivatePath="zhangdi;bin"></probing></assemblyBinding></runtime></configuration>
privatePath:指定检索程序集的路径
=====================测试:
Assemblya=Assembly.Load("ClassLibrary1,Version=1.0.0.0");Console.WriteLine(a.FullName);Console.ReadKey();
3,指定程序集版本
例如:最开始发布的程序集有些BUG,或者该程序集需要新的功能,就需要发布新的版本。
就需要我们在配置文件里面指定
<?xmlversion="1.0"encoding="utf-8"?><configuration><startup><supportedRuntimeversion="v4.0"sku=".NETFramework,Version=v4.5"/></startup><runtime><assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentityname="zhangdi"culture="neutral"publicKeyToken="c2b627ba3f19e9ae"/><bindingRedirectoldVersion="1.0.0.0-1.0.0.1"newVersion="1.0.0.1"></bindingRedirect></dependentAssembly></assemblyBinding></runtime></configuration>
oldVersion:必须设置,oldVersion特性指定应把程序集的哪个版本重定向到新版本上 。使用oldVersion特性可以指定一个范围。
newVersion:必须设置,指定新版本
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。