GAC程序集的版本使用基于程序Web.Config [英] GAC Assembly version to use based on Web.Config

查看:211
本文介绍了GAC程序集的版本使用基于程序Web.Config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好日子

我有一个项目,它使用在GAC中的自定义组件: 为了能够使用这个,我添加了一个引用到我的项目在

<$p$p><$c$c>C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\JOHN.CommonLib\v4.0_1.0.0.0__9cd884563ebafb62\JOHN.CommonLib.dll

(CopyLocal = FALSE; SpecificVersion = FALSE) 此外,我说这在web.config文件

 &LT;编译调试=假严=真明确=真正的targetFramework =4.0&GT;
  &LT;组件&GT;
    &LT;添加组件=JOHN.CommonLib,版本= 1.0.0.0,文化=中性公钥= 9cd884563ebafb62/&GT;
  &LT; /组件&GT;
&LT; /编译&GT;
 

它的运行符合预期。问题是,当我安装一个新的版本 我安装新版本的GAC,并相应地更改Web.config中

 &LT;添加组件=JOHN.CommonLib,版本= 2.0.0.0,文化=中性公钥= 9cd884563ebafb62/&GT;
 

JOHN.CommonLib是一个测试类库,返回无论是1.0或2.0根据不同的版本。

问题:如果我编译使用1.0,即使用它的web应用总是显示1.0,即使我改变1.0到2.0之间的Web.Config中 我想我的web应用程序使用,我写我的web.config的版本

任何想法? 我也停止和启动程序池在改变的Web.Config之间。

解决方案

有关强名称的程序集 - 应用程序始终绑定(如果可能),它已建成的版本。要覆盖这个绑定,需要指定绑定重定向程序集。有多种方法可以做到这一点 - 看到这链接。因此,一个使用的应用程序/ Web配置文件的方式 - 例如,

 &lt;结构&GT;
  &LT;运行&GT;
    &LT; assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1&GT;
      &LT; dependentAssembly&GT;
        &LT; assemblyIdentity名=JOHN.CommonLib
          公钥=9cd884563ebafb62
          文化=EN-US/&GT;
        &LT;! - 集版本,可以在应用重定向,
          出版商策略,或机配置文件。 - &GT;
        &LT; bindingRedirect oldVersion =1.0.0.0NEWVERSION =2.0.0.0/&GT;
      &LT; / dependentAssembly&GT;
    &LT; / assemblyBinding&GT;
  &LT; /运行&GT;
&LT; /结构&gt;
 

Good Day

I have a project that makes use of custom assemblies in the GAC: To be able to use that, I added a Reference to my project in

C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\JOHN.CommonLib\v4.0_1.0.0.0__9cd884563ebafb62\JOHN.CommonLib.dll

(CopyLocal=False; SpecificVersion=False) Also, i added this in the Web.Config file

<compilation debug="false" strict="true" explicit="true" targetFramework="4.0" >
  <assemblies>
    <add assembly="JOHN.CommonLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9cd884563ebafb62"/>        
  </assemblies >
</compilation >

It's running as expected. The problem is when i install a new version I install a new version to the GAC, and change the Web.Config accordingly

<add assembly="JOHN.CommonLib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=9cd884563ebafb62"/>

JOHN.CommonLib is a tester Class Library that returns either "1.0" or "2.0" depending on the version.

Issue: If I compile using 1.0, the webapps that make use of it always shows "1.0" even if i change the Web.Config between 1.0 and 2.0 I would like my web app to use the version that i write in my Web.Config

Any ideas? I also stop and start the AppPool in between changing the Web.Config.

解决方案

For strong named assemblies - application will always bind (if possible) to the version that it has been built with. To override this binding, you need to specify binding redirection for the assembly. There are multiple ways to do that - see this link. So one of the way to use app/web config file - for example,

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="JOHN.CommonLib"
          publicKeyToken="9cd884563ebafb62"
          culture="en-us" />
        <!-- Assembly versions can be redirected in application, 
          publisher policy, or machine configuration files. -->
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

这篇关于GAC程序集的版本使用基于程序Web.Config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆