【问题标题】:GAC Assembly version to use based on Web.Config基于 Web.Config 使用的 GAC 程序集版本
【发布时间】:2011-05-12 08:15:08
【问题描述】:

美好的一天

我有一个在 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 文件中添加了这个

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

它按预期运行。问题是当我安装一个新的版本 我为 GAC 安装了一个新版本,并相应地更改了 Web.Config

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

JOHN.CommonLib 是一个测试器类库,根据版本返回“1.0”或“2.0”。

问题:如果我使用 1.0 编译,使用它的 webapps 总是显示“1.0”,即使我在 1.0 和 2.0 之间更改 Web.Config 我希望我的网络应用程序使用我在 Web.Config 中编写的版本

有什么想法吗? 我还在更改 Web.Config 之间停止和启动 AppPool。

【问题讨论】:

    标签: .net asp.net gac


    【解决方案1】:

    对于强命名程序集 - 应用程序将始终绑定(如果可能)到它所构建的版本。要覆盖此绑定,您需要为程序集指定绑定重定向。有多种方法可以做到这一点 - 请参阅link。所以使用 app/web 配置文件的一种方式——例如,

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多