TeamCity中的MSBuild步骤考虑了app.config而不是ASP.NET WEB API项目的web.config,导致警告MSB3247

我有带有Web.conig文件的ASP.NET WEB API项目。 在VS2015中构建时,不会报告错误和警告。 但是,当我使用MSBuild构建步骤在TeamCity上构建此项目时,我收到警告MSB3247:

[ResolveAssemblyReferences] ResolveAssemblyReference [14:30:01] : [ResolveAssemblyReference] No way to resolve conflict between "protobuf-net, Version=2.0.0.602, Culture=neutral, PublicKeyToken=257b51d87d2e4d67" and "protobuf-net, Version=2.0.0.480, Culture=neutral, PublicKeyToken=257b51d87d2e4d67". Choosing "protobuf-net, Version=2.0.0.602, Culture=neutral, PublicKeyToken=257b51d87d2e4d67" arbitrarily. [14:30:01] : [ResolveAssemblyReference] No way to resolve conflict between "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". Choosing "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily. [14:30:01] : [ResolveAssemblyReference] Consider app.config remapping of assembly "protobuf-net, Culture=neutral, PublicKeyToken=257b51d87d2e4d67" from Version "2.0.0.602" [] to Version "2.0.0.668" [D:\TeamCity\buildAgent\work\2772494ce0e0bbd7\branches\Stategic.Window.Release1\src\Strategic.Window\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll] to solve conflict and get rid of warning. [14:30:01] : [ResolveAssemblyReference] Consider app.config remapping of assembly "Newtonsoft.Json, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" from Version "6.0.0.0" [] to Version "7.0.0.0" [D:\TeamCity\buildAgent\work\2772494ce0e0bbd7\branches\Stategic.Window.Release1\src\Strategic.Window\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll] to solve conflict and get rid of warning. [14:30:01] : [ResolveAssemblyReference] Consider app.config remapping of assembly "RazorEngine, Culture=neutral, PublicKeyToken=9ee697374c7e744a" from Version "3.0.8.0" [] to Version "3.7.4.0" [D:\TeamCity\buildAgent\work\2772494ce0e0bbd7\branches\Stategic.Window.Release1\src\Strategic.Window\packages\RazorEngine.3.7.4\lib\net45\RazorEngine.dll] to solve conflict and get rid of warning. [14:30:01] : [ResolveAssemblyReference] Consider app.config remapping of assembly "WebGrease, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "1.5.1.25624" [] to Version "1.5.2.14234" [D:\TeamCity\buildAgent\work\2772494ce0e0bbd7\branches\Stategic.Window.Release1\src\Strategic.Window\packages\WebGrease.1.5.2\lib\WebGrease.dll] to solve conflict and get rid of warning. [14:30:01]W: [ResolveAssemblyReference] C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819, 5): warning MSB3247: Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file:  

看起来app.config文件正在被MSBuild而不是Web.config考虑,因为它建议添加bindingRedirtect,它们已存在于我的Web.config文件中。 我通过复制粘贴Web.config并将其重命名为App.config来仔细检查。 这删除了警告。 删除App.config时 – 会再次出现警告。 所以我的问题是1)为什么虽然MSBuild似乎使用app.config并没有失败,当我在项目中只有Web.config时; 2)如何给MSBuild提示使用Web.config进行绑定重定向? 3)为什么在VS中构建完全相同的项目不会产生警告?

问题是未安装Microsoft Web Developer Tools。 在这种情况下,MSBuild不知道如何正确处理web.config文件。

可能的解决方案:

  1. 在TeamCity服务器上安装Microsoft ASP.NET和Web Tools 2015

  2. 将这些文件夹复制到TeamCity服务器

    • c:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v14.0 \ WebApplications \
    • c:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v14.0 \ Web \

    确保中的是正确的。

Microsoft.WebApplication.targets文件引用Web文件夹中的文件,因此它也必须就位。

从这里收获溶液。