需要配置配置文件
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();
3,指定程序集版本
例如:最开始发布的程序集有些BUG,或者该程序集需要新的功能,就需要发布新的版本。
就需要我们在配置文件里面指定
<?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="zhangdi" culture="neutral" publicKeyToken="c2b627ba3f19e9ae"/> <bindingRedirect oldVersion="1.0.0.0 - 1.0.0.1" newVersion="1.0.0.1"></bindingRedirect> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
oldVersion:必须设置,oldVersion特性指定应把程序集的哪个版本重定向到新版本上 。使用oldVersion特性可以指定一个范围。
newVersion:必须设置,指定新版本
转载于:https://blog.51cto.com/962410314/1589850