TeamCity中的MSBuild步骤考虑了ASP.NET web API项目的app.config而不是web.con

本文关键字:web 项目 API app con config NET MSBuild 中的 ASP TeamCity | 更新日期: 2023-09-27 18:26:47

我有一个带有WEB.config文件的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: <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,因为它建议添加bindingRedirect,而这些文件已经存在于我的Web.config文件中。我通过复制粘贴Web.config并将其重命名为App.config进行了双重检查。这消除了警告。删除App.config后,将再次出现警告。所以我的问题是:1)为什么MSBuild似乎在使用app.config,但当我在项目中只有Web.config时却没有失败;2) 如何提示MSBuild使用Web.config进行绑定重定向?3) 为什么在VS中构建完全相同的项目不会产生警告?

TeamCity中的MSBuild步骤考虑了ASP.NET web API项目的app.config而不是web.con

问题是没有安装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''

    确保web csproj中的<Import Project="$(VSToolsPath)'WebApplications'Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />是正确的。

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

溶液是从这里收获的。