MSBuild "GenerateFakes"错误 MSB4127,MSB4060



当使用Visual Studio 2013构建GenerateFakes成功时,它使用相同的路径到相同的目标文件。

通过MSBuild 12.0 (Visual Studio 2013附带的相同版本)构建时,我得到以下两个错误。

错误# 1

C:Program Files (x86)MSBuildMicrosoftVisualStudiov12.0FakesMicrosoft.QualityTools.Testing.Fakes.targets(128,5): error MSB4127: The "GenerateFakes" task could not be instantiated from the assembly "C:Program Files (x86)MSBuildMicrosoftVisualStudiov12.0FakesMicrosoft.QualityTools.Testing.Fakes.Tasks.dll". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.QualityTools.Testing.Fakes.GenerateFakes' to type 'Microsoft.Build.Framework.ITask'. 

错误#2

C:Program Files (x86)MSBuildMicrosoftVisualStudiov12.0FakesMicrosoft.QualityTools.Testing.Fakes.targets(128,5): error MSB4060: The "GenerateFakes" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.

我可以在使用Visual Studio 2012的旧机器上使用MSBuild 11.0成功构建。

这个问题可能与某种丢失的绑定重定向有关吗?

下面的链接包含一个类似的错误,但在另一个框架:http://social.msdn.microsoft.com/forums/vstudio/en-US/2772a075-4e2f-42af-9e7a-2228b794368e/msbuild-crashes-with-a-message-task-could-not-be-instantiated-exception

刚刚注意到删除所有项目中的FakeAssemblies文件夹解决了这个问题,但是一旦我在Visual Studio中构建,错误又回来了。

为了解决这个问题,我不得不在全局属性中将VisualStudioVersion设置为12.0。这需要在从命令行运行MSBuild.exe或使用MSBuild API时完成。

使用API:

我不得不手动引用MSBuild 12.0 dll,这些dll可以在Program Files (x86)MSBuild12.0Bin

中找到

接下来从MSBuild.exe.config复制程序集重定向并将它们粘贴到我的app.config中。

  <runtime>
    <DisableFXClosureWalk enabled="true" />
    <generatePublisherEvidence enabled="false" />
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="12.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build.Engine" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="12.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="12.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.CompactFramework.Build.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="12.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

查看Visual Studio项目(.csproj)文件的脚本。你可以在记事本中打开它。文件的ToolsVersion是什么?如果是4.0,则需要使用MSbuild 4.0来构建它。

Visual Studio 2013继续对toolVersion设置为4.0的项目使用MSBuild 4.0。

最新更新