问题描述
我米试图不针对一个DLL的一个特定版本,但我不十分清楚如何。
我已经设置的组件虚假的属性选择特定的版本,但是如果我尝试运行应用程序和要求集的版本是一前一,我得到一个:
I m trying to not target a specific version of a dll but I m not quite sure how.I have set the option Specific Version on the properties of the assembly to false, however if i try to run the application and the version of the requested assembly is a previous one, I get a:
FileLoadException: Could not load file or assembly
这是发生在被引用的DLL的版本并不完全当前的匹配。
我会相信这个问题是如何引用该组件。
This is happening when the version of the referenced dll does not exactly match the current one.I would believe that the issue is on how to reference this assembly.
推荐答案
在一般情况下,如果你想使用装配以下的特定版本并不真正适用,你应该只使用你所需要的版本。
In general, if you are trying to use a specific version of an assembly the below doesn't really apply, you should just use the version you need.
不过,有时你会遇到这样一种情况你有这样的:
However, sometimes you can run into a situation where you have this:
AssemblyX - 引用AssemblyZ
AssemblyY 1.2.1版本 - AssemblyZ
AssemblyX - references version 1.2.1 of AssemblyZ
AssemblyY - references version 1.2.2 of AssemblyZ
不过,您的项目需要两个AssemblyX 和的 AssemblyY。
But your project needs both AssemblyX and AssemblyY.
那么,如何解决这个问题?您可以把1.2.1和AssemblyZ 1.2.2在GAC中,或者,如果你确定没有任何兼容性问题,你可以使用汇编重新绑定。下面是一个例子(这正好在的Web.config
或的App.config
文件):
So how do you resolve this? You can either put 1.2.1 and 1.2.2 of AssemblyZ in the GAC, or, if you're sure there aren't any compatibility issues, you can use assembly rebinding. Here's an example (this goes in your Web.config
or App.config
file):
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
这是什么基本上说的是,如果解决方案中的任何参考MyAssembly的程序集的1.0.0.0,那么他们要真正使用版本2.0.0.0。而你预计有2.0.0.0版本中存在的路径。
What this basically says is that if any assemblies in your solution reference 1.0.0.0 of myAssembly, then they should really use version 2.0.0.0. And you're expected to have version 2.0.0.0 present in the path.
一个黑客可以使用,当你总是希望他们使用的组件的具体版本指定一个版本范围,就像这样:
A hack you can use when you always want them to use a specific version of the assembly is to specify a version range, like this:
<dependentAssembly>
<assemblyIdentity name="MyAssembly" publicKeyToken="B7567367622062C6" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="1.2.1.0" />
</dependentAssembly>
这将迫使MyAssembly程序的1.2.1.0版本将用于MyAssembly程序0.0之间的任何版本的参考。 0.0和3.0.0.0。
This will force version 1.2.1.0 of MyAssembly to be used for any version reference of MyAssembly between 0.0.0.0 and 3.0.0.0.
这篇关于目标的程序集的非特定版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!