asp.net-mvc - TFS 构建 2012、ASP.NET MVC 和 MSB3247 : Found conflicts between different versions of same dependent assembly

标签 asp.net-mvc msbuild web-config app-config tfsbuild

在 TFS Build 2012 下构建 Web 项目 (ASP.NET MVC4) 时,我收到 MS Build 警告“MSB3247:发现同一依赖程序集的不同版本之间存在冲突。”。

Consider app.config remapping of assembly "System.Web.Mvc, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "2.0.0.0" [] to Version "4.0.0.0" [XXXX\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll] to solve conflict and get rid of warning.

Consider app.config remapping of assembly "WebGrease, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "1.3.0.0" [] to Version "1.5.2.14234" [XXXX\packages\WebGrease.1.5.2\lib\WebGrease.dll] to solve conflict and get rid of warning.

Consider app.config remapping of assembly "Antlr3.Runtime, Culture=neutral, PublicKeyToken=eb42632606e9261f" from Version "3.4.1.9004" [] to Version "3.5.0.2" [XXXX\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll] to solve conflict and get rid of warning.

我知道哪些引用导致了这些问题,但这不是问题。我在 web.config 文件中设置了相关的绑定(bind)重定向,其中大部分是由 NuGet 在引用相关包时设置的。

问题是这是一个 Web 项目,就好像 MSBuild 忽略了 web.config 文件中的绑定(bind)重定向:

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>

此警告确实出现在本地开发人员构建中,但并非每次都一致。

有趣的是,如果我将 app.config 文件添加到 Web 项目并将程序集重定向放在那里(仍将原始重定向保留在 web.config 文件中),则会出现警告远程,本地和 TFS Build(始终如一地发生)。

什么鬼?有什么想法吗?

最佳答案

我终于成功地找出了这个错误的根本原因,并找出了一些转移注意力的问题。

首先,这是一个转移注意力的问题,在安装了 Visual Studio 2012 的地方不会发生该问题,或者在开发人员工作站上也不会发生该问题。虽然该问题始终出现在构建服务器 (TFS Build) 上,但如果遵循“批量清理全部”步骤,然后执行“构建”步骤,它也会发生在工作站上。

其次,我现在可以确认 MSB 3247 警告的罪魁祸首是 Microsoft BCL Build Nuget Package:

  • Microsoft.Bcl.Build.1.0.10

它修改 Web 应用程序项目文件,添加以下导入:

<Import Project="..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" />

<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
  <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
  <Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>

如果我将其从项目文件中注释掉,本地工作站和 TFS 构建服务器上的问题就会消失。

不幸的是,我不知道注释掉上述的真正含义是什么。我可以将其注释掉吗 - 会发生什么?

此 Microsoft.Bcl.Build NuGet 包是该项目的一部分的原因是它被标记为对我们使用的 Microsoft.Net.Http NuGet 包的依赖项。早期版本的 Microsoft.Net.Http NuGet 包没有对 Microsoft.Bcl 和 Microsoft.Bcl.Build 包的依赖。

希望这对某人有帮助。

PS:这里有一个相应的,但到目前为止没有帮助的论坛帖子:http://social.msdn.microsoft.com/Forums/vstudio/en-US/faa1b607-50bb-48e3-bd5d-76f4fc02ad4c/ms-build-gives-warning-msb3247-found-conflicts-between-different-versions-of-same-dependent?forum=msbuild

关于asp.net-mvc - TFS 构建 2012、ASP.NET MVC 和 MSB3247 : Found conflicts between different versions of same dependent assembly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18950949/

相关文章:

c# - 在 MVC 应用程序中使用 httpclient

c# - WCF 错误 自动生成的客户端和配置中的目标主体名称不正确

azure - 如何将 <clientCache/> 设置应用于 IIS 中的特定扩展?

authentication - 使用 user/pass 向 web.config 添加基本身份验证的最简单方法

javascript - ASP.NET MVC 客户端模型和 JavaScript

asp.net-mvc - Web Api 调用在服务器上返回 404

asp.net-mvc - ASP.NET MVC ActionLink 与 URL 重写

msbuild - 从 Nuget 包中引用 MSBuildTasks

.net - 仅当项目实际构建时才运行 MSBuild 目标

visual-studio-2013 - 使用 Microsoft.Build.Evaluation 解析实际引用路径