我目前正在开发一个。net应用程序,它由20个项目组成。其中一些项目是使用。net 3.5编译的,其他一些仍然是。net 2.0项目(到目前为止没有问题)。
问题是,如果我包含一个外部组件,我总是得到以下警告:
发现同一依赖程序集的不同版本之间存在冲突。
这个警告到底是什么意思,有没有可能排除这个警告(比如在源代码文件中使用#pragma disable)?
我目前正在开发一个。net应用程序,它由20个项目组成。其中一些项目是使用。net 3.5编译的,其他一些仍然是。net 2.0项目(到目前为止没有问题)。
问题是,如果我包含一个外部组件,我总是得到以下警告:
发现同一依赖程序集的不同版本之间存在冲突。
这个警告到底是什么意思,有没有可能排除这个警告(比如在源代码文件中使用#pragma disable)?
当前回答
如果你使用Nuget来管理依赖项,我还有另一种方法。我发现有时候VS和Nuget不匹配,Nuget无法识别你的项目不同步。的包。config会说一件事,但在References - Properties中显示的路径将指示其他内容。
如果你愿意更新你的依赖项,请执行以下操作:
From Solution Explorer, right click the Project and click 'Manage Nuget Packages' Select 'Installed packages' tab in left pane Record your installed packages You may want to copy your packages.config to your desktop first if you have a lot, so you can cross check it with Google to see what Nuget pkgs are installed Uninstall your packages. Its OK, we're going to add them right back. Immediately install the packages you need. What Nuget will do is not only get you the latest version, but will alter your references, and also add the binding redirects for you. Do this for all of your projects. At the solution level, do a Clean and Rebuild.
您可能希望从较低的项目开始,然后逐步到较高级别的项目,并在进行过程中重新构建每个项目。
如果你不想更新你的依赖项,那么你可以使用包管理器控制台,并使用语法update - package -ProjectName [yourProjectName] [packageName] -Version [versionNumber]
其他回答
我只是有这个警告消息,清理解决方案和重新编译(构建->清洁解决方案),它消失了。
我想在上面的评论中发布pauloya提供的解决方案。我相信这是找到冒犯性引用的最佳解决方案。
最简单的方法找到什么是“冒犯的引用”是 设置生成输出的详细信息(工具,选项,项目和解决方案, 构建和运行,MSBuild项目构建输出详细信息)和 构建之后,在输出窗口中搜索警告。查看原文 就在它上面。
例如,当你在输出面板中搜索“冲突”时,你可能会发现这样的东西:
3> There was a conflict between "EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".
3> "EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was chosen because it was primary and "EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was not.
正如您所看到的,EF版本5和6之间存在冲突。
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的最新版本,解决了这个问题!
我在我的一个项目中也遇到了同样的问题,然而,上面没有一个有助于解决警告。我检查了详细的构建日志文件,我使用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)
我希望上面的说明说明了我的意思,我花了几个小时才发现,所以希望其他人也能从中受益。
我也有同样的问题,我通过在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>