GAC程序集的版本使用基于程序Web.Config程序、版本、GAC、Web

2023-09-04 04:38:44 作者:劳资的心禁止访问

好日子

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

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文件

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

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

 <添加组件=JOHN.CommonLib,版本= 2.0.0.0,文化=中性公钥= 9cd884563ebafb62/>
 
ASP.NET 配置 Web.config

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

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

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

解决方案

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

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

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>