我目前正在开发一个。net应用程序,它由20个项目组成。其中一些项目是使用。net 3.5编译的,其他一些仍然是。net 2.0项目(到目前为止没有问题)。
问题是,如果我包含一个外部组件,我总是得到以下警告:
发现同一依赖程序集的不同版本之间存在冲突。
这个警告到底是什么意思,有没有可能排除这个警告(比如在源代码文件中使用#pragma disable)?
我目前正在开发一个。net应用程序,它由20个项目组成。其中一些项目是使用。net 3.5编译的,其他一些仍然是。net 2.0项目(到目前为止没有问题)。
问题是,如果我包含一个外部组件,我总是得到以下警告:
发现同一依赖程序集的不同版本之间存在冲突。
这个警告到底是什么意思,有没有可能排除这个警告(比如在源代码文件中使用#pragma disable)?
当前回答
我也有同样的问题,我通过在web.config中更改以下内容来解决。
这发生在我身上,因为我正在使用Newtonsoft运行应用程序。Json 4.0
来自:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
To:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
其他回答
另一件需要考虑和检查的事情是,确保没有任何正在运行的服务正在使用该bin文件夹。如果是,则停止服务并重新构建解决方案
在Visual Studio中,如果你右键单击解决方案并管理nuget包,会有一个“巩固”选项卡,它将所有的包设置为相同的版本。
我只是有这个警告消息,清理解决方案和重新编译(构建->清洁解决方案),它消失了。
此警告意味着两个项目引用相同的程序集(例如System.Windows.Forms),但这两个项目需要不同的版本。你有几个选择:
Recompile all projects to use the same versions (e.g. move all to .Net 3.5). This is the preferred option because all code is running with the versions of dependencies they were compiled with. Add a binding redirect. This will suppress the warning. However, your .Net 2.0 projects will (at runtime) be bound to the .Net 3.5 versions of dependent assemblies such as System.Windows.Forms. You can quickly add a binding redirect by double-clicking on error in Visual Studio. Use CopyLocal=true. I'm not sure if this will suppress the warning. It will, like option 2 above, mean that all projects will use the .Net 3.5 version of System.Windows.Forms.
这里有几个方法来识别不合适的推荐人:
您可以使用一个实用程序,例如在 https://gist.github.com/1553265 另一个简单的方法是设置Build 输出冗长(工具,选项,项目和解决方案,构建和 运行,MSBuild项目构建输出详细,详细)之后 构建时,在输出窗口中搜索警告,并查看 文字就在上面。(向保罗亚致敬,她在 对这个答案的评论)。
我在我的一个项目中也遇到了同样的问题,然而,上面没有一个有助于解决警告。我检查了详细的构建日志文件,我使用AsmSpy来验证我在受影响的解决方案中为每个项目使用了正确的版本,我仔细检查了每个项目文件中的实际条目-没有任何帮助。
最终发现,问题是我在一个项目中拥有的一个引用的嵌套依赖关系。该引用(A)反过来需要(B)的不同版本,后者直接从我的解决方案中的所有其他项目中引用。更新被引用项目中的引用解决了这个问题。
Solution A
+--Project A
+--Reference A (version 1.1.0.0)
+--Reference B
+--Project B
+--Reference A (version 1.1.0.0)
+--Reference B
+--Reference C
+--Project C
+--Reference X (this indirectly references Reference A, but with e.g. version 1.1.1.0)
Solution B
+--Project A
+--Reference A (version 1.1.1.0)
我希望上面的说明说明了我的意思,我花了几个小时才发现,所以希望其他人也能从中受益。