MSBuild"GenerateFakes"错误MSB4127,MSB4060 [英] MSBuild "GenerateFakes" Error MSB4127, MSB4060

查看:188
本文介绍了MSBuild"GenerateFakes"错误MSB4127,MSB4060的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When building using Visual Studio 2013 the GenerateFakes succeeds, it uses the same path to the same target file.

通过MSBuild 12.0(Visual Studio 2013附带的相同版本)进行构建时,出现以下两个错误.

When building via MSBuild 12.0 (Same version shipped with Visual Studio 2013) I get the following two errors.

错误#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'. 

错误#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.

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

I could successfully build using MSBuild 11.0 on an old machine which was using Visual Studio 2012.

该问题是否与某种缺少绑定重定向有关?

以下链接包含类似的错误,但适用于另一个框架:

The following link contains a similar error but for another framework: 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时,都需要这样做.

To fix the issue i've had to set the VisualStudioVersion to 12.0 in the global properties. This needs to be done both when running MSBuild.exe from the command line, or when using the MSBuild API.

使用API​​:

我不得不手动引用可以在Program Files (x86)\MSBuild\12.0\Bin

I have had to manually reference the MSBuild 12.0 Dlls which can be found in Program Files (x86)\MSBuild\12.0\Bin

接下来,复制了MSBuild.exe.config中的程序集重定向并将其粘贴到我的app.config中.

Next copied the assembly redirects from MSBuild.exe.config and pasted them into my 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>

这篇关于MSBuild"GenerateFakes"错误MSB4127,MSB4060的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆