.net 发现同一依赖程序集的不同版本之间无法解决的冲突

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24772053/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:47:03  来源:igfitidea点击:

Found conflicts between different versions of the same dependent assembly that could not be resolved

.netvisual-studiomsbuildvisual-studio-express

提问by Water Cooler v2

When I clean and then build my solution that has several projects, the output window reports that the build succeeded. However, when I view the Error List Window, it shows me this warning:

当我清理并构建包含多个项目的解决方案时,输出窗口报告构建成功。但是,当我查看Error List Window 时,它向我显示此警告:

Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets

发现同一依赖程序集的不同版本之间无法解决的冲突。当日志详细程度设置为详细时,这些引用冲突会在构建日志中列出。C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets

When I double-click this message, it opens the C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targetsfile but I don't understand anything in it.

当我双击此消息时,它会打开C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets文件,但我不明白其中的任何内容。

I am using Visual Studio Express 2013 for the Web.

我在 Web 上使用 Visual Studio Express 2013。

How do I find out what's wrong and with which DLL and how do I then make the warning go away?

我如何找出问题所在以及哪个 DLL 出现问题,然后如何使警告消失?

回答by Ruben Bartelink

eta: There's a killer article on this stuff by SO's own @Nick Craverthat you should read

eta:SO 自己的 @Nick Craver一篇关于这些东西杀手文章,你应该阅读



While the other responses say this, they don't make it explicit, so I will....

虽然其他回复这么说,但他们没有明确说明,所以我会......

On VS2013.2, to actually trigger the emission of the cited information, you need to not read the message, which says:

在VS2013.2上,要真正触发引用信息的发射,你不需要阅读消息,它说:

C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.

C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5):警告 MSB3277:发现同一依赖程序集的不同版本之间存在无法解决的冲突。当日志详细程度设置为details 时,这些引用冲突会在构建日志中列出。

This is incorrect (or at least it was for some versions of Visual Studio - it seems to be OK on an up to date VS2015 Update 3 or later). Instead turn it to Diagnostic(from Tools->Options->Project and Solutions->Build and Run, set MSBuild project build output verbosity), whereupon you'll see messages such as:

这是不正确的(或者至少对于某些版本的 Visual Studio 是错误的 - 在最新的 VS2015 Update 3 或更高版本上似乎没问题)。而是将其转为诊断(从Tools->Options->Project and Solutions->Build and Run,设置MSBuild 项目构建输出 verbosity),然后您将看到如下消息:

There was a conflict between "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=6.0.5.17707, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed".

  • "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" was chosen because it was primary and "Newtonsoft.Json, Version=6.0.5.17707, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" was not.

“Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”和“Newtonsoft.Json, Version=6.0.5.17707, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”之间存在冲突。

  • 选择“Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”是因为它是主要的,而“Newtonsoft.Json, Version=6.0.5.17707, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”不是。

Then

然后

  • Ctrl-Alt-Oto go to Build output window
  • search for "was chosen" to find the drilldown.
  • Ctrl-Alt-O转到构建输出窗口
  • 搜索“被选择”以查找明细。

...And yes, for those looking at the detail of the [diagnostic] message, it was news to this ignoramus that there's a convention in town whereby all 6.xversions are, internally Assembly Version 6.0.0.0, i.e. only the SemVer Major component goes into the Assembly Version:)

...是的,对于那些查看 [诊断] 消息细节的人来说,对于这个无知的人来说,这是一个新闻,城里有一个约定,所有6.x版本在内部都是组装版本6.0.0.0,即只有 SemVer 主要组件进入组装版本:)

回答by Ilya Kozhevnikov

Run msbuild Foo.sln /t:Rebuild /v:diag(from C:\Program Files (x86)\MSBuild\12.0\bin) to build your solution from command line and get a bit more details, then find the .csproj.that logs the warning and check its references and references of other projects that use the same common assembly that differs in version.

运行msbuild Foo.sln /t:Rebuild /v:diag(from C:\Program Files (x86)\MSBuild\12.0\bin) 以从命令行构建您的解决方案并获取更多详细信息,然后找到.csproj.记录警告的 并检查其引用以及使用版本不同的相同公共程序集的其他项目的引用。

Edit: You can also set the build verbosity directly in VS2013. Go to Tools> Optionsmenu then go to Projects and Solutionsand set MSBuild verbosity to Diagnostic.

编辑:您也可以直接在 VS2013 中设置构建详细程度。转到Tools>Options菜单,然后转到Projects and Solutions并将 MSBuild 详细程度设置为Diagnostic.

Edit: Few clarifications as I just got one myself. In my case warning was due to me adding a reference using Resharper prompt as opposed to the Add Reference dialog, which did it versionless even though both v4 and v12 are available to choose from.

编辑:几乎没有澄清,因为我自己刚刚得到了一个。在我的情况下,警告是由于我使用 Resharper 提示添加了一个引用,而不是添加引用对话框,即使 v4 和 v12 都可以选择,它也没有版本。

<Reference Include="Microsoft.Build, Version=12.0.0.0, ..." />
<Reference Include="Microsoft.Build.Framework" />

vs

对比

<Reference Include="Microsoft.Build, Version=12.0.0.0, ..." />
<Reference Include="Microsoft.Build.Framework, Version=12.0.0.0, ..." />

In the MSBuild log with /v:diagverbosity it looked like the following. giving details which two references conflicted:-

/v:diag详细的 MSBuild 日志中,它看起来如下所示。提供两个参考文献冲突的详细信息:-

  There was a conflict between 
  "Microsoft.Build.Framework, Version=4.0.0.0, ..." and 
  "Microsoft.Build.Framework, Version=12.0.0.0, ...". (TaskId:16)

      "Microsoft.Build.Framework, Version=4.0.0.0, ..." was chosen because it was primary and 
      "Microsoft.Build.Framework, Version=12.0.0.0, ..." was not. (TaskId:16)

      References which depend on "Microsoft.Build.Framework, Version=4.0.0.0, ..." 
      [C:\...\v4.5.1\Microsoft.Build.Framework.dll]. (TaskId:16)

          C:\...\v4.5.1\Microsoft.Build.Framework.dll (TaskId:16)
            Project file item includes which caused reference "C:\...\v4.5.1\Microsoft.Build.Framework.dll". (TaskId:16)
              Microsoft.Build.Framework (TaskId:16)

      References which depend on "Microsoft.Build.Framework, Version=12.0.0.0, ..." 
      [C:\...\v12.0\Microsoft.Build.Framework.dll]. (TaskId:16)

          C:\...\v12.0\Microsoft.Build.dll (TaskId:16)
            Project file item includes which caused reference "C:\...\v12.0\Microsoft.Build.dll". (TaskId:16)
              Microsoft.Build, Version=12.0.0.0, ... (TaskId:16)

          C:\...\v12.0\Microsoft.Build.Engine.dll (TaskId:16)
            Project file item includes which caused reference "C:\...\v12.0\Microsoft.Build.Engine.dll". (TaskId:16)
              Microsoft.Build, Version=12.0.0.0, ... (TaskId:16)

C:\Program Files (x86)\MSBuild.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3277: 
Found conflicts between different versions of the same dependent assembly that could not be resolved.  
These reference conflicts are listed in the build log when log verbosity is set to detailed. 
[C:\Users\Ilya.Kozhevnikov\Dropbox\BuildTree\BuildTree\BuildTree.csproj]

回答by Alexander Christov

I can only support further Ruben's answer with a comparison between the two messages displayed:

我只能通过比较显示的两条消息来进一步支持鲁本的回答:

enter image description here

在此处输入图片说明

and the message:

和消息:

C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.

C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5):警告 MSB3277:发现同一依赖程序集的不同版本之间存在无法解决的冲突。这些参考冲突在构建日志中列出当日志级别设置为详细

So, Ruben's right—this is just not true. There are no conflicts whatsoever, just a missing assembly. This is especially boring when the project is an ASP.NET application, since the views are compiled on demand, that is, just before displayed for the first time. This is when it becomes necessary to have the assembly available. (There's an option to pre-compile the views together with the rest of the code, but this is another story.) On the other hand, if you set the verbosity to Diagnosticyou get the following output:

所以,鲁本是对的——这不是真的。没有任何冲突,只是缺少程序集。当项目是 ASP.NET 应用程序时,这尤其无聊,因为视图是按需编译的,即在第一次显示之前。这是有必要使组件可用的时候。(有一个选项可以将视图与其余代码一起预编译,但这是另一回事。)另一方面,如果将详细程度设置为诊断,则会得到以下输出:

C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL".Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5):警告 MSB3245:无法解析此引用。无法找到程序集“System.Web.Razor,Version=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL”。检查以确保程序集存在于磁盘上。如果您的代码需要此引用,您可能会收到编译错误。

As a result, all you need to do is either:

因此,您需要做的就是:

  1. Add a reference to the assembly manually (locate it on disk, maybe GAC, and add it as a "direct" reference), or
  2. Use NuGet package (if published in the gallery) to download it and reference the assembly contained within it.
  1. 手动添加对程序集的引用(在磁盘上找到它,可能是 GAC,并将其添加为“直接”引用),或
  2. 使用 NuGet 包(如果在库中发布)下载它并引用其中包含的程序集。

More about NuGet gallery here. More about precompiling ASP.NET views here.

有关 NuGet 库的更多信息,请访问此处。有关预编译 ASP.NET 视图的更多信息,请点击此处

回答by sree

Changing the build verbosity in visual studio will help to point in the right direction. Follow the below steps to change verbosity in VS

在 Visual Studio 中更改构建详细程度将有助于指明正确的方向。按照以下步骤更改 VS 中的详细程度

  1. Go to Tools->Options menu in VS
  2. Open Projects and Solutions->Build and Run
  3. Change the value of the MSBuild project build output verbosity. Pick one from Quiet, Minimal, Normal, Detailedand Diagnostic
  1. 转到工具-> VS 中的选项菜单
  2. 打开项目和解决方案->构建和运行
  3. 更改 MSBuild 项目生成输出详细程度的值。选择一个距离QuietMinimalNormalDetailedDiagnostic

Check the output window(Ctrl+Alt+O) in VS to see the changes in the build log.

检查输出窗口(Ctrl+ Alt+O中VS)看到生成日志的变化。

回答by Shaswat Rungta

Reiterating one of the comments from @elshev Right click on the solution -> Manage NuGet packages for solution -> Under Consolidate you can see if there are different versions of the same package was installed. Update the packages there. The conflict error is resolved.

重申@elshev 的评论之一 右键单击​​解决方案 -> 管理解决方案的 NuGet 包 -> 在合并下,您可以查看是否安装了同一包的不同版本。更新那里的软件包。冲突错误已解决。

回答by CrazyPyro

and how do I then make the warning go away?

然后我如何使警告消失?

You are probably going to have to reinstallor upgrade your NuGet packages to fix this.

您可能需要重新安装或升级您的 NuGet 包来解决这个问题。

回答by RandomHandle

I'm using Visual Studio 2017 and encountered this when I updated some Nuget packages. What worked for me was to open my web.configfile and find the <runtime><assemblyBinding>node and delete it. Save web.configand rebuild the project.

我正在使用 Visual Studio 2017 并在更新一些 Nuget 包时遇到了这个问题。对我有用的是打开我的web.config文件并找到<runtime><assemblyBinding>节点并将其删除。保存web.config并重建项目。

Look at the Error Listwindow. You'll see what looks like a massively long warning about binding conflicts. Double-click it and it will automatically recreate the <runtime><assemblyBinding>block with the correct mappings.

看看Error List窗户。您将看到关于绑定冲突的长篇警告。双击它,它将自动重新创建<runtime><assemblyBinding>具有正确映射的块。

回答by Jose L. Garcia

As stated in dotnet CLI issue 6583the issue should be solved with dotnet nuget locals --clear allcommand.

dotnet CLI 问题 6583 中所述,应使用dotnet nuget locals --clear all命令解决该问题。

回答by joelmdev

Obviously there's a lot of different causes and thus a lot of solutions for this problem. To throw mine into the mix, we upgraded an assembly (System.Net.Http) that was previously directly referenced in our Web project to a version managed by NuGet. This removed the direct reference within that project, but our Test project still contained the direct reference. Upgrading both projects to use the NuGet-managed assembly resolved the issue.

显然,这个问题有很多不同的原因,因此有很多解决方案。为了将我的加入其中,我们将之前在我们的 Web 项目中直接引用的程序集 (System.Net.Http) 升级到由 NuGet 管理的版本。这删除了该项目中的直接引用,但我们的 Test 项目仍然包含直接引用。升级这两个项目以使用 NuGet 管理的程序集解决了该问题。

回答by Carolina

I could solve this installing Newtonsoft Json in the web project with nugget packages

我可以用 nugget 包解决这个在 web 项目中安装 Newtonsoft Json 的问题