.NET绑定重定向进行编译 [英] .NET Binding Redirection for Compilation

查看:101
本文介绍了.NET绑定重定向进行编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试编译使用已部署到客户端的文件的实用程序时,出现以下错误。

I'm getting the following error when I try and compile a utility, which uses files that have been deployed to our client.


程序集'* A *版本2.0.1.2'使用的'* B *版本1.1.39.0'的版本高于引用的程序集'* B *版本1.1.32.0'。

Assembly '*A* version 2.0.1.2' uses '*B* version 1.1.39.0' which has a higher version than referenced assembly '*B* version 1.1.32.0'.

我们的客户端可以毫无问题地使用这些DLL,因为我们有一个绑定重定向配置文件,该文件在运行时生效:

Our client can use these DLLs no problem, because we have a binding redirection config file in place, which takes effect at run-time:

<dependentAssembly>
  <assemblyIdentity name="*B*" publicKeyToken="..." culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.1.32.0" />
</dependentAssembly>

为了提供一些背景知识,这些DLL存在于单独的解决方案中,因此有些参考文献是文件引用而不是项目引用,只是我必须忍受的东西!

To give a bit of background, the DLLs exist in separate solutions, and therefore some of the references are file references rather than project references, just something I have to live with!

在编译时是否存在任何等效的绑定重定向?

我尝试使用调试DLL(版本1.0.0.0)进行编译,并且源代码回滚到上述相关版本,但是在运行时出现以下错误:

I've tried compiling using debug DLLs (version 1.0.0.0), with source rolled back to the relevant version above, however I get the following error at run-time:


找到的程序集的清单定义与程序集引用不匹配

The located assembly's manifest definition does not match the assembly reference

也许构建服务器的配置与我的机器不同,但是无论如何似乎都不起作用...

Maybe the build server is configured differently to my machine, but anyway that didn't seem to work...

推荐答案

我怀疑是否可以根据需要修复它。如果您阅读有关该编译错误的文档( https://msdn.microsoft.com/en-us/library /416tef0c.aspx ),您将会看到既可以更新代码以使用相同版本,也可以在编译期间引用这两个版本(在您的情况下不是一个选择)。

I doubt it's possible to "fix" it as you want to. If you read documentation for that compile error (https://msdn.microsoft.com/en-us/library/416tef0c.aspx), you will see that you can either update code to use the same version, or reference both versions during compilation (not an option in your case).

想象一下,该版本1.0.0.0包含方法MyMethod(),但版本1.0.0.1包含MyMethod(string),并且第一个版本由程序集A使用,第二个版本由正在编译的程序集使用。您希望编译器如何解决此问题?在运行时中,当您使用绑定重定向时,仅一个版本的程序集将仍被加载。在这里,您没有程序集A的代码(您要引用该代码,而程序集又引用了MyMethod),并且对程序集1.0.0.0的引用嵌入在A的清单中。

Imagine, that version 1.0.0.0 contains method MyMethod(), but version 1.0.0.1 contains MyMethod(string), and first version is used by assembly A, second version is used by assembly you are compiling. How do you want compiler to resolve this? In runtime, when you use binding redirection, only one version of assembly will be loaded still. Here, you do not own code for assembly A (which you are refering to, and which in turn references MyMethod), and reference to assembly 1.0.0.0 is embedded in A's manifest.

长话短说-我想为您解决的唯一方法是使用程序集A,该程序集与您引用的版本相同。

Long story short - I suppose only way to solve it for you is use assembly A which references the same version of B as you do.

这篇关于.NET绑定重定向进行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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