程序集版本控制

版本组成: 主版本号.次版本号.构建次数.修订号 四部分组成,

<major version>.<minor version>.<build number>.<revision>,

[assembly: AssemblyVersion( " 2.1.* " )]

 

版本号在强名称程序集中才能显示出它的唯一性控制的,以下都是针对 强名称程序集 来阐述的。

 

程序集重定向:

1、应用程序级别:通过配置文件app.config/web.config中设置重定向元素

ContractedBlock.gif ExpandedBlockStart.gif VersionRedirect
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    
<runtime>
        
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            
<probing privatePath="libs"/>
            
<dependentAssembly>
                
<assemblyIdentity name="MathLibrary"
                    publicKeyToken
="8210BDCE54DAB3C2"/>
                
<bindingRedirect oldVersion="1.1.1.1" 
                    newVersion
="1.1.2.2"/>    
            
</dependentAssembly>
        
</assemblyBinding>
    
</runtime>
</configuration>

 

2、机器范围级别:于machine.config中(${.NET Install Path}\Config\Machine.config),

    找到<runtime>元素节点中,进行版本重定向控制。

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\mscorcfg.msc .NET框架配置工具

3、发布者策略:不同于1、2中的配置文件,它是程序集本身,其原理如下:不通过修改

app/web.config/machine.confg,而通过发布到GAC中的版本策略(一程序集),改变调用的

程序集的新的定向,其命名约定:policy.<major version>.<minor version>.<assemblyName>

举例:设MathLibrary.dll强名称程序集存在2版本: 1.1.2.2 和 1.1.3.3,

1、编辑策略文件 publisherpolicy.xml 

ContractedBlock.gif ExpandedBlockStart.gif publisherpolicy.xml
<configuration>
    
<runtime>
        
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            
<dependentAssembly>
                
<assemblyIdentity name="MathLibrary"
                    publicKeyToken
="8210BDCE54DAB3C2"/>
                
<bindingRedirect oldVersion="1.1.2.2" 
                    newVersion
="1.1.3.3"/>    
            
</dependentAssembly>
        
</assemblyBinding>
    
</runtime>
</configuration>

 

2、生成策略程序集,使用al命令(C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\al.exe)

al /link:publisherpolicy.xml /out:policy.1.1.MathLibrary.dll /keyf:http://www.cnblogs.com/../myKey.snk /v:1.0.0.0

 

3、安装1.1.3.3版本的A.dll & policy.1.1.MathLibrary.dll 到GAC中。

此后所有对1.1.2.2的请求都会被转至1.1.3.3版本的MathLibrary上。

 

codeBase: codeBase所指定位置范围的有效性,于普通/强名称程序集的区别,可参见 私有程序集探测 一节中

的描述,这里仅demo之以明用法,如上发布者策略中,可通过修改publisherpolicy.xml文件来重定向

ContractedBlock.gif ExpandedBlockStart.gif publisherpolicy.xml
<configuration>
    
<runtime>
        
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            
<dependentAssembly>
                
<assemblyIdentity name="MathLibrary"
                    publicKeyToken
="8210BDCE54DAB3C2"/>
                
<bindingRedirect oldVersion="1.1.2.2" 
                    newVersion
="1.1.3.3"/>        
                
<codeBase version="1.1.3.3" 
                    href
="file://D:\project\net\assembly\SimpleMath\bin\Debug\MathLibrary.dll"/>
            
</dependentAssembly>
        
</assemblyBinding>
    
</runtime>
</configuration>

 

策略优先级别:

应用配置文件(app.confg/web.config)、发布者策略文件、机器配置文件(高->低)

 

关闭发布者策略: 可通过设置在应用配置文件中关闭发布者策略(注意:是应用程序配置文件中,

因为有优先级关系),可配置为应用程序范围级别的和某个具体的程序集范围的。如下:

ContractedBlock.gif ExpandedBlockStart.gif 应用程序范围级别
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    
<runtime>
        
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            
<publisherPolicy apply="no"/>
        
</assemblyBinding>
    
</runtime>
</configuration>

 

ContractedBlock.gif ExpandedBlockStart.gif 程序集级别
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    
<runtime>
        
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            
<dependentAssembly>
                
<assemblyIdentity name="MathLibrary"
                    publicKeyToken
="8210BDCE54DAB3C2"/>
                
<publisherPolicy apply="no"/>
            
</dependentAssembly>
        
</assemblyBinding>
    
</runtime>
</configuration>

 

 

转载于:https://www.cnblogs.com/FallingAutumn/archive/2008/07/28/1254244.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值