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

发布于 2024-11-07 09:36:16 字数 999 浏览 5 评论 0原文

美好的一天,

我有一个在 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 进行编译,即使我在 1.0 和 2.0 之间更改 Web.Config,使用它的 Web 应用程序也始终显示“1.0” 我希望我的网络应用程序使用我在 Web.Config 中编写的版本

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巨坚强 2024-11-14 09:36:16

对于强命名程序集 - 应用程序将始终绑定(如果可能)到它所构建的版本。要覆盖此绑定,您需要为程序集指定绑定重定向。有多种方法可以做到这一点 - 请参阅此链接。因此,使用 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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文