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

我知道哪些引用导致了这些,这不是问题。我在 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>
此警告确实发生在本地开发人员构建中,但并非每次都一致。
有趣的是,如果我向 web 项目添加一个 app.config 文件并将程序集重定向放在那里(仍然在 web.config 文件中保留原始重定向)警告消失,本地和 TFS Build(它发生的地方)始终如一。)。
跆拳道?有任何想法吗?

最佳答案

我终于设法隔离了这个错误的根本原因并确定了一些红鲱鱼。

首先,在安装 Visual Studio 2012 或开发人员工作站上不会发生此问题是一个红鲱鱼。虽然该问题始终出现在构建服务器 (TFS 构建) 上,但它也会发生在工作站上,前提是遵循“批量清理所有”和“构建”步骤。

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

  • 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/

    10-13 07:48
    查看更多