TeamCity 中的 MSBuild 步骤将 app.config 而不是 web.config 用于 ASP.NET WEB API 项目,导致警告 MSB3247
MSBuild step in TeamCity considers app.config instead of web.config for ASP.NET WEB API project resulting in warning MSB3247
我有 ASP.NET WEB API 项目和 Web.conig 文件。当它在 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\work72494ce0e0bbd7\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\work72494ce0e0bbd7\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\work72494ce0e0bbd7\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\work72494ce0e0bbd7\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.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: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="protobuf-net" culture="neutral" publicKeyToken="257b51d87d2e4d67" /><bindingRedirect oldVersion="0.0.0.0-2.0.0.668" newVersion="2.0.0.668" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /><bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="RazorEngine" culture="neutral" publicKeyToken="9ee697374c7e744a" /><bindingRedirect oldVersion="0.0.0.0-3.7.4.0" newVersion="3.7.4.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" /><bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /></dependentAssembly></assemblyBinding>
看起来 MSBuild 正在考虑 app.config 文件而不是 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 文件。
可能的解决方案:
在 TeamCity 服务器上安装 Microsoft ASP.NET 和 Web Tools 2015
将这些文件夹复制到 TeamCity 服务器
- c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\
- c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\
确保web csproj中的<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
是正确的。
文件 Microsoft.WebApplication.targets 引用 Web 文件夹中的文件,因此,它也必须存在。
解决方案来自 here。
我有 ASP.NET WEB API 项目和 Web.conig 文件。当它在 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\work72494ce0e0bbd7\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\work72494ce0e0bbd7\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\work72494ce0e0bbd7\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\work72494ce0e0bbd7\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.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: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="protobuf-net" culture="neutral" publicKeyToken="257b51d87d2e4d67" /><bindingRedirect oldVersion="0.0.0.0-2.0.0.668" newVersion="2.0.0.668" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /><bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="RazorEngine" culture="neutral" publicKeyToken="9ee697374c7e744a" /><bindingRedirect oldVersion="0.0.0.0-3.7.4.0" newVersion="3.7.4.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" /><bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /></dependentAssembly></assemblyBinding>
看起来 MSBuild 正在考虑 app.config 文件而不是 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 文件。
可能的解决方案:
在 TeamCity 服务器上安装 Microsoft ASP.NET 和 Web Tools 2015
将这些文件夹复制到 TeamCity 服务器
- c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\
- c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\
确保web csproj中的
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
是正确的。
文件 Microsoft.WebApplication.targets 引用 Web 文件夹中的文件,因此,它也必须存在。
解决方案来自 here。