gpt4 book ai didi

visual-studio - MSBuild "GenerateFakes"错误 MSB4127、MSB4060

转载 作者:行者123 更新时间:2023-12-04 05:33:33 32 4
gpt4 key购买 nike

当使用 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'. 

错误#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 成功构建。

这个问题可能与某种缺少绑定(bind)重定向有关吗?

以下链接包含类似的错误,但针对另一个框架: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:

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

接下来从 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 - MSBuild "GenerateFakes"错误 MSB4127、MSB4060,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23759705/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com