.net 解决 MSB3247 - 发现同一依赖程序集的不同版本之间存在冲突
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1871073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Resolving MSB3247 - Found conflicts between different versions of the same dependent assembly
提问by David Gardiner
A .NET 3.5 solution ended up with this warning when compiling with msbuild.
.NET 3.5 解决方案在使用 msbuild 编译时最终出现此警告。
Sometimes NDepend might help out but in this case it didn't give any further details. Like BobI ended up having to resort to opening each assembly in ILDASM until I found the one that was referencing an older version of the dependant assembly.
有时 NDepend 可能会有所帮助,但在这种情况下,它没有提供任何进一步的细节。像 Bob 一样,我最终不得不在 ILDASM 中打开每个程序集,直到我找到引用旧版本依赖程序集的程序集。
I did try using MSBUILD from VS 2010 Beta 2 (as the Connect article indicated this was fixed in the next version of the CLR) but that didn't provide any more detail either (maybe fixed post Beta 2)
我确实尝试使用 VS 2010 Beta 2 中的 MSBUILD(因为 Connect 文章指出这已在下一版本的 CLR 中修复)但也没有提供更多细节(可能在 Beta 2 后修复)
Is there a better (more automated) approach?
有没有更好(更自动化)的方法?
回答by AMissico
Change the "MSBuild project build output verbosity" to "Detailed" or above. To do this, follow these steps:
将“MSBuild 项目构建输出详细程度”更改为“详细”或更高版本。为此,请按照下列步骤操作:
- Bring up the Options dialog (Tools -> Options...).
- In the left-hand tree, select the Projects and Solutionsnode, and then select Build and Run.
- Note: if this node doesn't show up, make sure that the checkbox at the bottom of the dialog Show all settingsis checked.
In the tools/options page that appears, set the MSBuild project build output verbositylevel to the appropriate setting depending on your version:
- Diagnosticswhen on VS2012, VS2013 or VS2015 (the message in these versions saysyou should use "Detailed", but this is plain wrong, you should use "Diagnostics")
- Detailedwhen you're on VS2010
- Normalwill suffice in VS2008 or older.
- Build the project and look in the output window.
- 调出选项对话框(工具 -> 选项...)。
- 在左侧树中,选择Projects and Solutions节点,然后选择Build and Run。
- 注意:如果此节点未显示,请确保选中对话框显示所有设置底部的复选框。
在出现的工具/选项页面中,根据您的版本将MSBuild 项目构建输出详细级别设置为适当的设置:
- 在 VS2012、VS2013 或 VS2015 上进行诊断(这些版本中的消息说您应该使用“Detailed”,但这是完全错误的,您应该使用“Diagnostics”)
- VS2010 上的详细介绍
- 在 VS2008 或更早的版本中,Normal就足够了。
- 构建项目并查看输出窗口。
Check out the MSBuild messages. The ResolveAssemblyReferencestask, which is the task from which MSB3247 originates, should help you debug this particular issue.
查看 MSBuild 消息。该ResolveAssemblyReferences任务是 MSB3247 的起源任务,应该可以帮助您调试这个特定问题。
My specific case was an incorrect reference to SqlServerCe. See below. I had two projects referencing two different versions of SqlServerCe. I went to the project with the older version, removed the reference, then added the correct reference.
我的具体情况是对 SqlServerCe 的错误引用。见下文。我有两个项目引用了两个不同版本的 SqlServerCe。我去了旧版本的项目,删除了引用,然后添加了正确的引用。
Target ResolveAssemblyReferences:
Consider app.config remapping of assembly "System.Data.SqlServerCe, ..."
from Version "3.5.1.0" [H:\...\Debug\System.Data.SqlServerCe.dll]
to Version "9.0.242.0" [C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies\System.Data.SqlServerCe.dll]
to solve conflict and get rid of warning.
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets :
warning MSB3247: Found conflicts between different versions of the same dependent assembly.
You do not have to open each assembly to determine the versions of referenced assemblies.
您不必打开每个程序集来确定引用程序集的版本。
- You can check the Properties of each Reference.
- Open the project properties and check the versions of the References section.
- Open the projects with a Text Editor.
- Use .Net Reflector.
- 您可以检查每个参考的属性。
- 打开项目属性并检查参考部分的版本。
- 使用文本编辑器打开项目。
- 使用 .Net 反射器。
回答by Noel Abrahams
Mike Hadlow has posted a little console app called AsmSpythat rather nicely lists each assembly's references:
Mike Hadlow发布了一个名为 AsmSpy 的小控制台应用程序,它很好地列出了每个程序集的引用:
Reference: System.Net.Http.Formatting
4.0.0.0 by Shared.MessageStack
4.0.0.0 by System.Web.Http
Reference: System.Net.Http
2.0.0.0 by Shared.MessageStack
2.0.0.0 by System.Net.Http.Formatting
4.0.0.0 by System.Net.Http.WebRequest
2.0.0.0 by System.Web.Http.Common
2.0.0.0 by System.Web.Http
2.0.0.0 by System.Web.Http.WebHost
This is a much quicker way to get to the bottom of the warning MSB3247, than to depend on the MSBuild output.
与依赖 MSBuild 输出相比,这是深入了解 MSB3247 警告的更快方法。
回答by Jaider
Sometime @AMissico answer is not enough. In my case, I couldn't find the error in the Output windows so I decided to create a log file and analyze it, by doing the following steps:
有时@AMissico 的回答是不够的。就我而言,我在“输出”窗口中找不到错误,因此我决定通过执行以下步骤创建一个日志文件并对其进行分析:
Saving the build log to a file... https://msdn.microsoft.com/en-us/library/ms171470.aspx
msbuild MyProject.proj /fl /flp:logfile=MyProjectOutput.log;verbosity=detailedFind the text:
warning MS...or the specific warning info: (e.g. line 9293)Found conflicts between different versions...and the full detail of the conflict error will be above of this message (e.g. line 9277)There was a conflicts between...
将构建日志保存到文件... https://msdn.microsoft.com/en-us/library/ms171470.aspx
msbuild MyProject.proj /fl /flp:logfile=MyProjectOutput.log;verbosity=detailed查找文本:
warning MS...或特定警告信息:(例如第 9293 行)Found conflicts between different versions...,冲突错误的完整详细信息将在此消息的上方(例如第 9277 行)There was a conflicts between...
Visual Studio 2013
视觉工作室 2013
回答by ErikHeemskerk
I found that (at least in Visual Studio 2010) you need to set the output verbosity to at least Detailed to be able to spot the problem.
我发现(至少在 Visual Studio 2010 中)您需要将输出详细程度至少设置为“详细”才能发现问题。
It might be that my problem was a reference that was previously a GAC reference, but that was no longer the case after my machine's reinstall.
可能是我的问题是以前是 GAC 引用的引用,但在我的机器重新安装后不再是这种情况。
回答by Carol
I had the same error and could not figure it out with the other answers. I found that we can "Consolidate" NuGet packages.
我有同样的错误,无法用其他答案弄清楚。我发现我们可以“整合”NuGet 包。
- Right click on the solution
- Click Manage Nuget Packages
- Consolidate tab and update to the same version.
- 右键单击解决方案
- 单击管理 Nuget 包
- 合并选项卡并更新到相同版本。
回答by RouR
This warning generated for default ASP.NET MVC 4 beta see here
为默认 ASP.NET MVC 4 beta 生成的此警告 请参见此处
In, any cast this Warning can be eliminated by manually editing the .csproj file for your project.
modify........: Reference Include="System.Net.Http"
to read ......: Reference Include="System.Net.Http, Version=4.0.0.0"
在,可以通过手动编辑项目的 .csproj 文件来消除任何投射此警告。
修改........:参考 Include="System.Net.Http"
阅读......:参考 Include="System.Net.Http, Version=4.0.0.0"
回答by Manitra Andriamitondra
Use a dependency reader
使用依赖阅读器
Using dep.exeyou can list out all the nested dependencies of an entire folder. Combined with unix tools like grep or awk, it can help you to solve your problem
使用dep.exe可以列出整个文件夹的所有嵌套依赖项。结合 grep 或 awk 等 unix 工具,它可以帮助您解决问题
Finding assemblies being referenced in more than one version
查找在多个版本中引用的程序集
$ dep | awk '{ print " " ; print " " }' | awk '{ if (length(versions[]) == 0) versions[] = ; if (versions[] != ) errors[] = ; } END{ for(e in errors) print e } '
System.Web.Http
This obscure command line runs dep.exe then pipes the output twice to awk to
这个晦涩的命令行运行 dep.exe 然后将输出两次通过管道传送到 awk
- put the parent and child in a single column (by default each line contains one parent and a child to express the fact that this parent depends of that child)
- then do a kind of 'group by' using an associative array
- 将父级和子级放在一列中(默认情况下,每行包含一个父级和一个子级,以表达此父级依赖于该子级的事实)
- 然后使用关联数组做一种“分组依据”
Understanding how this assembly got pulled in your bin
了解这个组件是如何被拉进你的垃圾箱的
$ dep myproject/bin | grep -i System\.Web\.Http
MyProject-1.0.0.0 >> System.Web.Http.Web-5.2.3.0 2 ( FooLib-1.0.0.0 )
MyProject-1.0.0.0 >> System.Web.Http.Web-4.0.0.0 2 ( BarLib-1.0.0.0 )
FooLib-1.0.0.0 > System.Web.Http.Web-5.2.3.0 1
BarLib-1.0.0.0 > System.Web.Http.Web-4.0.0.0 1
In this example, the tool would show you that System.Web.Http 5.2.3 comes from your dependency to FooLib whereas the version 4.0.0 comes from BarLib.
在此示例中,该工具将向您显示 System.Web.Http 5.2.3 来自您对 FooLib 的依赖,而 4.0.0 版本来自 BarLib。
Then you have the choice between
然后你可以选择
- convincing the owners of the libs to use the same version
- stop using one them
- adding binding redirects in your config file to use the latest version
- 说服库的所有者使用相同的版本
- 停止使用其中之一
- 在配置文件中添加绑定重定向以使用最新版本
How to run these thing in Windows
如何在 Windows 中运行这些东西
If you don't have a unix type shell you'll need to download one before being able to run awkand grep. Try one of the following
如果您没有 unix 类型的 shell,则需要先下载一个,然后才能运行awk和grep. 尝试以下方法之一
回答by Hamiora
I had this problem too and used AMissico's advice too discover the problem (Although had to set verbosity level to Detailed.
我也遇到了这个问题,并使用了 AMissico 的建议来发现问题(尽管必须将详细级别设置为详细。
The problem was actually quite straight forward though after finding the culprit.
尽管在找到罪魁祸首之后,问题实际上很简单。
Background: I upgraded my project from VS2008 to VS2010. In VS2008 the target framework was 3.5 and when I brought it into VS2010 I switched it to 4 (Full). I also upgraded some third party components including Crystal reports.
背景:我将我的项目从 VS2008 升级到 VS2010。在 VS2008 中,目标框架是 3.5,当我将其引入 VS2010 时,我将其切换为 4(完整)。我还升级了一些第三方组件,包括 Crystal 报表。
It turned out most of System references where pointing at version 4.0.0.0 but a couple had not been automatically changed (System and System.Web.Services) and were still looking at 2.0.0.0. Crystal reports is referencing 4.0.0.0 and so this was where the conflicts were occuring. Simply putting the cursor at the first System library in the solution explorer, cursor down the list and looking for any references to 2.0.0.0, removing and re-adding newer 4.0.0.0 version did the trick.
事实证明,大多数 System 引用都指向 4.0.0.0 版,但有一些没有自动更改(System 和 System.Web.Services)并且仍在查看 2.0.0.0。Crystal 报告引用了 4.0.0.0,因此这就是发生冲突的地方。只需将光标放在解决方案资源管理器中的第一个系统库上,向下移动列表并查找对 2.0.0.0 的任何引用,删除并重新添加较新的 4.0.0.0 版本即可解决问题。
The strange this was that most of the references had been correctly updated and if it weren't for Crystal reports, I probably would never had noticed...
奇怪的是,大多数参考资料都已正确更新,如果不是 Crystal 报告,我可能永远不会注意到......
回答by lex87
回答by Eric Ouellet
I made an application based on Mike Hadlow application: AsmSpy.
我基于Mike Hadlow 应用程序制作了一个应用程序: AsmSpy。
My app is a WPF app with GUI and can be download from my home webserver: AsmSpyPlus.exe.
我的应用程序是一个带有 GUI 的 WPF 应用程序,可以从我的家庭网络服务器下载:AsmSpyPlus.exe。
Code is available at: GitHub
代码可在:GitHub

