如何在 Vsix 扩展中执行 dll bindingRedirect? [英] How to do dll bindingRedirect in a Vsix extension?

查看:34
本文介绍了如何在 Vsix 扩展中执行 dll bindingRedirect?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 VS 扩展,它应该使用 Gmail api 向我公司的某些用户发送邮件.在开发过程中,我遇到了 System.Net.Http.Primitives 版本的一个常见问题,该问题在 Google API 中以某种方式搞砸了.

I have an extension to VS that should use Gmail api to send mails to certain users in my company. During development I step into a common issue with System.Net.Http.Primitives version that is somehow messed up in Google API.

常见解决方案 用于将 bindingRedirect 放在 app.config 中,以将所有调用重定向到库的最新版本.如下图:

The common solution for this is to put bindingRedirect in app.config to redirectall calls to a new up-to-date version of the library. Like below:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
      <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>

但是,如果我的输出是 Vsix 包,这似乎不起作用.生成的 Vsix 甚至没有 app.config.

However, this seems not to work in case when my output is a Vsix package. Generated Vsix doesn't even have an app.config.

我知道一个解决方案说将 bindingRedirect 添加到 machine.config 文件,但我的扩展被其他一些人使用,我不想强​​迫他们将东西放入他们的机器配置文件中.

I'm aware of a solution that says to add bindingRedirect to machine.config file but my extensions is used by some other people and I would rather not force them to put stuff into their machine configuration files.

是否有其他解决方案?

推荐答案

从技术上讲,app.config 属于进程 (.exe),而不属于 dll.对于 Visual Studio,它是位于 C:\Program Files (x86)\Microsoft Visual Studio \Common7\IDE 的 devenv.exe.config 文件.

Technically, the app.config belongs to the process (.exe), not to the dlls. For Visual Studio, it is the devenv.exe.config file located at C:\Program Files (x86)\Microsoft Visual Studio <version>\Common7\IDE.

但是要修改该文件,您的扩展程序应该以管理员权限安装(即 .msi 或类似的安装程序技术).而且我认为修改该文件不是一个好主意,因为它会影响其他扩展.

But to modify that file your extension should be installed with admin rights (that is, .msi or similar installer technology). And I don't think it's a good idea to modify that file since it would affect other extensions.

您可以尝试的一种方法是通过代码重定向绑定,以某种方式强制程序集解析失败,订阅 AppDomain.AssemblyResolveEvent,以获得提供您想要的确切程序集的机会.请参阅:http://blog.slaks.net/2013-12-25/redirecting-assembly-loads-at-runtime/

One approach that you can try is to redirect binding by code somehow forcing an assembly resolution failure, subscribing to the AppDomain.AssemblyResolveEvent, to get a chance of providing the exact assembly that you want. See: http://blog.slaks.net/2013-12-25/redirecting-assembly-loads-at-runtime/

这篇关于如何在 Vsix 扩展中执行 dll bindingRedirect?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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