如何在Vsix扩展名中执行DLL bindingRedirect? [英] How to do dll bindingRedirect in a Vsix extension?
问题描述
我有一个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< version> \ 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屋!