MSBuild"GenerateFakes"错误MSB4127,MSB4060

Jac*_*ack 3 msbuild visual-studio microsoft-fakes visual-studio-2013

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

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

错误#1

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Fakes\Microsoft.QualityTools.Testing.Fakes.targets(128,5): error MSB4127: The "GenerateFakes" task could not be instantiated from the assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Fakes\Microsoft.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'. 
Run Code Online (Sandbox Code Playgroud)

错误#2

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Fakes\Microsoft.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.
Run Code Online (Sandbox Code Playgroud)

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

该问题可能与某种缺失的绑定重定向有关吗?

以下链接包含类似的错误,但对于另一个框架:http://social.msdn.microsoft.com/forums/vstudio/en-US/2772a075-4e2f-42af-9e7a-2228b794368e/msbuild-crashes-with-a-消息任务可以-不能被实例化的异常

只是注意到删除所有项目中的FakeAssemblies文件夹可以解决问题,但是一旦我再次在Visual Studio中构建,错误就会恢复.

Jac*_*ack 6

要解决这个问题,我必须在全局属性中将VisualStudioVersion设置为12.0.从命令行运行MSBuild.exe或使用MSBuild API时,都需要执行此操作.

使用API​​:

我不得不手动引用可以找到的MSBuild 12.0 Dll Program Files (x86)\MSBuild\12.0\Bin

接下来复制程序集重定向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>
Run Code Online (Sandbox Code Playgroud)