简体   繁体   English

如何在C#应用程序中将GAC程序集与特定版本一起使用

[英]How to use GAC assembly with specific version in C# app

I have 2 GAC assemblies called AAA (version 1.0.0.0 and version 2.0.0.0). 我有2个称为AAA(1.0.0.0版和2.0.0.0版)的GAC程序集。 The application currently is using version 1 (reference added by Browse-for-assembly, path is hardcoded to this file), but I want to use version 2. 该应用程序当前正在使用版本1(通过浏览浏览器添加的引用,路径已硬编码到此文件),但是我想使用版本2。

To do it smoothly, I added some code to app.config: 为了顺利进行,我在app.config中添加了一些代码:

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

But application still is using version 1.0.0.0 of assembly, why? 但是应用程序仍在使用汇编版本1.0.0.0,为什么?

      culture="en-us" />

That's wrong, assemblies that contain code are always neutral. 错了,包含代码的程序集始终是中立的。 Only satellite assemblies have culture. 只有附属程序集具有文化。 Or in other words, your bindingRedirect doesn't match any of the assemblies that the app is asking for. 换句话说,您的bindingRedirect与应用程序要求的任何程序集都不匹配。 So has no effect. 所以没有效果。 Be sure to delete the assembly from the project's bin\\Debug directory so you can diagnose mistakes like this. 确保从项目的bin \\ Debug目录中删除程序集,以便您可以诊断类似的错误。 The Fuslogvw.exe utility is also very handy, log all binds. Fuslogvw.exe实用程序也非常方便,可以记录所有绑定。

Fix: 固定:

      culture="neutral" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM