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

发现同一依赖程序集的不同版本之间存在无法解决的冲突。当日志详细信息设置为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,然后我如何使警告消失?


当前回答

运行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]

其他回答

请注意,我通过将AutoGenerateBindingRedirects放在csproj文件中的TargetFramework之后解决了这个问题:

<TargetFramework>net462</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

在将包从nuget切换到本地引用dll后,我遇到了这个问题。这个问题是app.config中的旧的运行时绑定。

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

在visual studio中改变构建的冗长将有助于指向正确的方向。按照以下步骤更改VS中的详细信息

进入工具->选项菜单在VS 开放项目和解决方案->构建和运行 更改MSBuild项目构建输出详细信息的值。选择 分别是安静、最小、正常、详细和诊断

检查VS中的输出窗口(Ctrl+Alt+O),查看构建日志中的更改。

您可以运行Dotnet CLI进行详细的诊断,以帮助查找问题。

Dotnet运行——verbose diagnostic >> full_build.log

构建完成后,您可以通过日志文件(full_build.log)搜索错误。例如,搜索“一个冲突”,应该会把你直接带到问题所在。