[英]Resolving MSB3247 - Found conflicts between different versions of the same dependent assembly
A .NET 3.5 solution ended up with this warning when compiling with msbuild. 在使用msbuild进行编译时,.NET 3.5解决方案最终出现此警告。
Sometimes NDepend might help out but in this case it didn't give any further details. 有时NDepend可能有所帮助,但在这种情况下,它没有提供任何进一步的细节。 Like Bob I 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.
像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? 有更好的(更自动化的)方法吗?
Change the "MSBuild project build output verbosity" to "Detailed" or above. 将“MSBuild项目构建输出详细程度”更改为“详细”或更高版本。 To do this, follow these steps:
为此,请按照下列步骤操作:
In the tools/options page that appears, set the MSBuild project build output verbosity level to the appropriate setting depending on your version: 在出现的工具/选项页面中,根据您的版本将MSBuild项目构建输出详细级别设置为适当的设置:
Check out the MSBuild messages. 查看MSBuild消息。 The
ResolveAssemblyReferences
task, which is the task from which MSB3247 originates, should help you debug this particular issue. ResolveAssemblyReferences
任务(MSB3247发起的任务)应该可以帮助您调试此特定问题。
My specific case was an incorrect reference to SqlServerCe. 我的具体情况是对SqlServerCe的错误引用。 See below.
见下文。 I had two projects referencing two different versions of SqlServerCe.
我有两个项目引用了两个不同版本的SqlServerCe。 I went to the project with the older version, removed the reference, then added the correct reference.
我用旧版本去了项目,删除了引用,然后添加了正确的引用。
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. 您不必打开每个程序集来确定引用程序集的版本。
Mike Hadlow has posted a little console app called AsmSpy that 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. 这是一种更快速的方法来获取警告MSB3247的底部,而不是依赖于MSBuild输出。
Sometime @AMissico answer is not enough. 有时@AMissico回答是不够的。 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:
在我的情况下,我无法在输出窗口中找到错误,所以我决定创建一个日志文件并通过执行以下步骤进行分析:
Saving the build log to a file... https://msdn.microsoft.com/en-us/library/ms171470.aspx 将构建日志保存到文件... https://msdn.microsoft.com/en-us/library/ms171470.aspx
msbuild MyProject.proj /fl /flp:logfile=MyProjectOutput.log;verbosity=detailed
Find the text: warning MS...
or the specific warning info: (eg line 9293) Found conflicts between different versions...
and the full detail of the conflict error will be above of this message (eg line 9277) There was a conflicts between...
查找文本:
warning MS...
或特定的警告信息:(例如行9293) Found conflicts between different versions...
和冲突误差的全部细节将高于此消息的(如线9277) There was a conflicts between...
Visual Studio 2013 Visual Studio 2013
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参考的引用,但在我的机器重新安装后不再是这种情况。
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.
在,可以通过手动编辑项目的.csproj文件来消除任何强制转换此警告。
modify........: Reference Include="System.Net.Http"
修改........:参考包含=“System.Net.Http”
to read ......: Reference Include="System.Net.Http, Version=4.0.0.0"
阅读......:参考包含=“System.Net.Http,Version = 4.0.0.0”
I had the same error and could not figure it out with the other answers. 我有同样的错误,无法用其他答案搞清楚。 I found that we can "Consolidate" NuGet packages.
我发现我们可以“整合”NuGet包。
Using dep.exe you can list out all the nested dependencies of an entire folder. 使用dep.exe,您可以列出整个文件夹的所有嵌套依赖项。 Combined with unix tools like grep or awk, it can help you to solve your problem
结合使用grep或awk等unix工具,它可以帮助您解决问题
$ dep | awk '{ print $1 " " $2; print $4 " " $5 }' | awk '{ if (length(versions[$1]) == 0) versions[$1] = $2; if (versions[$1] != $2) errors[$1] = $1; } 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
$ 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 然后你可以选择
If you don't have a unix type shell you'll need to download one before being able to run awk
and grep
. 如果你没有unix类型的shell,你需要先下载一个shell才能运行
awk
和grep
。 Try one of the following 请尝试以下方法之一
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. 背景:我将我的项目从VS2008升级到VS2010。 In VS2008 the target framework was 3.5 and when I brought it into VS2010 I switched it to 4 (Full).
在VS2008中,目标框架是3.5,当我把它带到VS2010时,我把它切换到4(Full)。 I also upgraded some third party components including Crystal reports.
我还升级了一些第三方组件,包括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. 事实证明,大多数系统引用指向版本4.0.0.0,但一对未被自动更改(System和System.Web.Services),并且仍在查看2.0.0.0。 Crystal reports is referencing 4.0.0.0 and so this was where the conflicts were occuring.
Crystal报告引用了4.0.0.0,因此发生了冲突。 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.
只需将光标放在解决方案资源管理器中的第一个系统库中,向下光标列表并查找对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报告,我可能永远不会注意到......
如前所述在这里 ,你需要删除未使用的引用,并警告会去。
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 。
Quick Fix: 快速解决:
Right click on solution -> Manage NuGet packages for solution -> Under Consolidate you can see if there are different versions of the same package were installed. 右键单击解决方案 - >管理NuGet包以获得解决方案 - >在Consolidate下,您可以查看是否安装了相同软件包的不同版本。 Uninstall different versions and install the latest one.
卸载不同版本并安装最新版本。
Sometimes AutoGenerateBindingRedirects
isn't enough (even with GenerateBindingRedirectsOutputType
). 有时
AutoGenerateBindingRedirects
是不够的(即使使用GenerateBindingRedirectsOutputType
)。 Searching for all the There was a conflict
entries and fixing them manually one by one can be tedious, so I wrote a small piece of code that parses the log output and generates them for you (dumps to stdout
): 搜索所有
There was a conflict
条目并逐个手动修复它们可能很乏味,所以我写了一小段代码来解析日志输出并为你生成它们(转储到stdout
):
// Paste all "there was a conflict" lines from the msbuild diagnostics log to the file below
const string conflictFile = @"C:\AssemblyConflicts.txt";
var sb = new StringBuilder();
var conflictLines = await File.ReadAllLinesAsync(conflictFile);
foreach (var line in conflictLines.Where(l => !String.IsNullOrWhiteSpace(l)))
{
Console.WriteLine("Processing line: {0}", line);
var lineComponents = line.Split('"');
if (lineComponents.Length < 2)
throw new FormatException("Unexpected conflict line component count");
var assemblySegment = lineComponents[1];
Console.WriteLine("Processing assembly segment: {0}", assemblySegment);
var assemblyComponents = assemblySegment
.Split(",")
.Select(kv => kv.Trim())
.Select(kv => kv.Split("=")
.Last())
.ToArray();
if (assemblyComponents.Length != 4)
throw new FormatException("Unexpected conflict segment component count");
var assembly = assemblyComponents[0];
var version = assemblyComponents[1];
var culture = assemblyComponents[2];
var publicKeyToken = assemblyComponents[3];
Console.WriteLine("Generating assebmly redirect for Assembly={0}, Version={1}, Culture={2}, PublicKeyToken={3}", assembly, version, culture, publicKeyToken);
sb.AppendLine($"<dependentAssembly><assemblyIdentity name=\"{assembly}\" publicKeyToken=\"{publicKeyToken}\" culture=\"{culture}\" /><bindingRedirect oldVersion=\"0.0.0.0-{version}\" newVersion=\"{version}\" /></dependentAssembly>");
}
Console.WriteLine("Generated assembly redirects:");
Console.WriteLine(sb);
Tip: use MSBuild Binary and Structured Log Viewer and only generate binding redirects for the conflicts in the project that emits the warning (that is, only past those there was a conflict
lines to the input text file for the code above [ AssemblyConflicts.txt
]). 提示:使用MSBuild二进制和结构化日志查看器 ,仅为发出警告的项目中的冲突生成绑定重定向(即,只有那些与上面的代码的输入文本文件
there was a conflict
行的那些[ AssemblyConflicts.txt
] )。
ASP.NET build manager is building the website by going through the folders alphabetically, and for each folder it figures out it dependencies and builds the dependencies first and then the selected folder. ASP.NET构建管理器通过按字母顺序浏览文件夹来构建网站,并为每个文件夹确定其依赖关系并首先构建依赖关系,然后构建所选文件夹。
In this case the problematic folder which is ~/Controls, is selected to be built at the beginning, from yet an unknown reason, it builds some of the controls there as a separate assembly instead of inside the same assembly as other controls (seems to be connected to the fact that some controls are dependent on other controls in the same folder). 在这种情况下,有问题的文件夹〜/ Controls,被选择在开头构建,从一个未知的原因,它构建一些控件作为一个单独的程序集,而不是在与其他控件相同的程序集内(似乎连接到某些控件依赖于同一文件夹中的其他控件的事实。
Then the next folder which is built (~/File-Center/Control) is dependent on the root folder ~/ which is dependent on ~/Controls, so the folder ~/Controls is being built again only this time the controls which were separated to their own assembly are now joined to the same assembly as other controls with the separated assembly still being referenced. 然后构建的下一个文件夹(〜/ File-Center / Control)依赖于根文件夹〜/依赖于〜/ Controls,所以文件夹〜/ Controls只是这次被重新构建的控件被分离了现在,它们与自己的程序集连接到与其他控件相同的程序集,并且仍然引用了分离的程序集。
So at this point 2 assembly (at least) have the same controls and the build fails. 所以在这一点上,2个程序集(至少)具有相同的控件,并且构建失败。
Although we still don't know why this happened, we were able to work around it by changing the Controls folder name to ZControls, this way it is not built before ~/File-Center/Control, only after and this way it is built as it should. 虽然我们仍然不知道为什么会发生这种情况,但我们可以通过将Controls文件夹名称更改为ZControls来解决它,这样它就不会在〜/ File-Center / Control之前构建,只有在它构建之后才这样构建它正如它应该。
A simplest way without without one taking into account of (internal) dependencies : 没有考虑(内部)依赖关系的最简单方法:
In my case, there was a problem with MySQL reference. 就我而言,MySQL引用存在问题。 Somehow, I could list three versions of it under the list of all available references.
不知何故,我可以在所有可用引用列表下列出它的三个版本。 I followed process 1 through 6 above and it worked for me.
我按照上面的过程1到6进行了操作,它对我有用。
As AMissico's answer requires changing the log level, and neither ASMSpy nor ASMSpyPlus are available as a cross-platform solution, here is a short addition for Visual Studio for Mac: 由于AMissico的答案需要更改日志级别,ASMSpy和ASMSpyPlus都不能作为跨平台解决方案使用,因此这是Visual Studio for Mac的一个简短补充:
https://docs.microsoft.com/en-us/visualstudio/mac/compiling-and-building
https://docs.microsoft.com/en-us/visualstudio/mac/compiling-and-building
It's in Visual Studio Community → Preferences... → Projects → Build Log → verbosity 它位于Visual Studio社区 →首选项...→项目→构建日志→详细程度
如果您有resharper,请删除解决方案中所有未使用的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.