visual-studiomsbuildvisual-studio-2013microsoft-fakes

MSBuild "GenerateFakes" Error MSB4127, MSB4060


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

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

Error #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'. 

Error #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.

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

Could the issue be related to some sort of missing binding redirect?

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

Just noticed that deleting the FakeAssemblies folder in all projects cures the problem, however once I build in Visual Studio again the error comes back.


Solution

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

    Using the API:

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

    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>