我目前正在开发一个。net应用程序,它由20个项目组成。其中一些项目是使用。net 3.5编译的,其他一些仍然是。net 2.0项目(到目前为止没有问题)。

问题是,如果我包含一个外部组件,我总是得到以下警告:

发现同一依赖程序集的不同版本之间存在冲突。

这个警告到底是什么意思,有没有可能排除这个警告(比如在源代码文件中使用#pragma disable)?


当前回答

在花了几个小时分析详细的构建日志之后,我发现我的解决方案中的几个项目针对的是不同的. net版本。我将它们全部更改为. net 4.7.2并重新构建解决方案,错误得到解决。

其他回答

此警告意味着两个项目引用相同的程序集(例如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项目构建输出详细,详细)之后 构建时,在输出窗口中搜索警告,并查看 文字就在上面。(向保罗亚致敬,她在 对这个答案的评论)。

下面是解决方案,.NET Core 3.0风格: https://github.com/HTD/ref-check

当你发现哪些冲突时,也许你就能解决这些冲突。 如果冲突的引用来自其他包,那么您要么不走运,要么需要使用源。

在我的例子中,冲突的包通常是我自己的,所以我可以修复依赖关系问题并重新发布它们。

如果使用NuGet,我所要做的是:

右键单击项目,单击管理NuGet包.. 点击右上角的齿轮 在包源上方的NuGet包管理器中单击“常规”选项卡 检查“跳过应用绑定重定向”在绑定重定向 清理重建,警告就没了

容易peasy

I just spent sometime debugging the same issue. Note, that issue might not be between different projects, but actually between several references in one project that depend on different versions of the same dll/assembly. In my case, issue was reference FastMember.dll versions mismatch that comes from two different NuGet packages in a single project. When I was given a project, it would not compile because NuGet packages were missing and VS refused to restore missing packages. Through the NuGet menu, I manually update all the NuGets to the latest version, that is when the warning appeared.

在Visual Studio工具中>选项>构建和运行> msbuild项目构建输出详细信息:(设置为)诊断。在“输出”窗口中查找有冲突的行。下面是我得到的输出部分:

1>  There was a conflict between "FastMember, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null" and "FastMember, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null". (TaskId:19)
1>      "FastMember, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null" was chosen because it was primary and "FastMember, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" was not. (TaskId:19)
1>      References which depend on "FastMember, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null" [C:\Users\ksd3jvp\Source\Temp\AITool\Misra\AMSAITool\packages\FastMember.1.5.0\lib\net461\FastMember.dll]. (TaskId:19)
1>          C:\Users\ksd3jvp\Source\Temp\AITool\Misra\AMSAITool\packages\FastMember.1.5.0\lib\net461\FastMember.dll (TaskId:19)
1>            Project file item includes which caused reference "C:\Users\ksd3jvp\Source\Temp\AITool\Misra\AMSAITool\packages\FastMember.1.5.0\lib\net461\FastMember.dll". (TaskId:19)
1>              FastMember, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL (TaskId:19)
1>      References which depend on "FastMember, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" []. (TaskId:19)
1>          C:\Users\ksd3jvp\Source\Temp\AITool\Misra\AMSAITool\packages\ClosedXML.0.94.2\lib\net46\ClosedXML.dll (TaskId:19)
1>            Project file item includes which caused reference "C:\Users\ksd3jvp\Source\Temp\AITool\Misra\AMSAITool\packages\ClosedXML.0.94.2\lib\net46\ClosedXML.dll". (TaskId:19)
1>              ClosedXML, Version=0.94.2.0, Culture=neutral, processorArchitecture=MSIL (TaskId:19)

注意,该项目文件项包括导致引用“C:\Users\ksd3jvp\Source\Temp\AITool\Misra\AMSAITool\packages\ClosedXML.0.94.2\lib\net46\ClosedXML.dll”

ClosedXML.dll来自ClosedXML NuGet,它依赖于FastMember.dll 1.3.0.0。在它之上,项目中还有FastMember Nuget,它有FastMember.dll 1.5.0.0。不匹配!

我已经卸载了ClosedXML和FastMember NuGets,因为我有绑定重定向,并安装了ClosedXML的最新版本,解决了这个问题!

打开“解决方案资源管理器”。 点击“显示所有文件” 扩大“引用” 您将看到一个(或多个)引用与其他引用的图标略有不同。通常情况下,它会有一个黄色的方框,建议你记下它。把它拿掉。 重新添加引用并编译代码。 这是所有。

在我的例子中,MySQL引用有一个问题。不管怎样,我可以在所有可用的引用列表下列出它的三个版本;适用于。net 2.0、。net 4.0和。net 4.5。我遵循了上面的方法1到6,它对我很有效。