当我清理并构建具有多个项目的解决方案时,输出窗口将报告构建成功。然而,当我查看错误列表窗口时,它向我显示了这样的警告:

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

当我双击此消息时,它将打开C:\Program Files (x86)\MSBuild\12.0\bin\ Microsoft.Common.CurrentVersion。目标文件,但我不明白任何东西在它。

我正在使用Visual Studio Express 2013的Web。

我如何找出什么是错误的,与哪个DLL,然后我如何使警告消失?


当前回答

I found that, sometimes, nuget packages will install (what I'm guessing are) .NET Core required components or other items that conflict with the already-installed framework. My solution there was to open the project (.csproj) file and remove those references. For example, System.IO, System.Threading and such, tend to be added when Microsoft.Bcl is included via some recently installed NuGet package. There's no reason for specific versions of those in my projects, so I remove the references and the project builds. Hope that helps.

您可以在项目文件中搜索“参考”并删除冲突。如果它们包含在系统中,那么去掉它们,构建应该可以工作。这可能不能回答这个问题的所有情况-我确保你知道什么对我有用:)

我注释掉的例子:

< !<参考Include=“系统。”Runtime,版本=2.6.9.0,Culture=neutral, PublicKeyToken= b03f5f7f3a, processorArchitecture=MSIL"> -> < !- <HintPath>$(解决方案)packages\Microsoft.Bcl.1.1.9\lib\net40\系统. runtpath > < !<Private>True</Private> -> < !</参考> ->

其他回答

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

编辑:你也可以在VS2013中直接设置构建细节。转到工具>选项菜单,然后转到项目和解决方案,将MSBuild verbose设置为诊断。

编辑:有些澄清,因为我自己也有一个。在我的例子中,警告是由于我使用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, ..." />

在使用/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\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:\Users\Ilya.Kozhevnikov\Dropbox\BuildTree\BuildTree\BuildTree.csproj]

VS 2017, MVC项目

我不知道为什么,但对我来说,这个问题的解决方案是从控制器动作方法调用的模型方法签名中删除一个out参数。这是非常奇怪的行为,但这是我问题的解决方案。

我该如何让警告消失呢?

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

重申@elshev的评论 右键单击解决方案->管理解决方案->的NuGet包在巩固下,你可以看到是否有不同版本的相同的包被安装。在那里更新包。解决冲突错误。

eta: SO自己的@Nick Craver写了一篇关于这方面的杀手级文章,你应该读一下


虽然其他的回答是这样说的,但他们并没有明确表示,所以我将....

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

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

这是不正确的(或者至少在某些版本的Visual Studio中是这样的——在VS2015更新3或更高的版本中似乎是可以的)。相反,将其转到诊断(从工具->选项->项目和解决方案->构建和运行,设置MSBuild项目构建输出verbose),这时你会看到如下消息:

“牛顿软”和“牛顿软”之间存在冲突。Json,版本=6.0.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed"和"牛顿软。Json,版本=6.0.5.17707,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed"。 “Newtonsoft。Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”被选中是因为它是primary和“Newtonsoft. Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”。Json,版本=6.0.5.17707,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed"不是。

Then

按Ctrl-Alt-O进入构建输出窗口 搜索“was chosen”可以找到下钻。

...是的,对于那些看[诊断]信息细节的人来说,这对这个无知的人来说是新闻,在城里有一个公约,所有6。x版本在内部是Assembly Version 6.0.0.0,即只有SemVer Major组件进入Assembly Version:)