Could not run the “GenerateResource” task because MSBuild could not create or connect to a task host with runtime “CLR2” and architecture “x86”.

Since I have experienced the same error more than three times while creating Windows Service (.NET 3.5) on Visual Studio 2012 and/or 2013, I think I should post a solution here for my quick reference. If you create a Windows Service and target .NET 3.5 on Visual Studio 2012 or 2013, you might experience the error message while compiling the project.

Here is the full error message:

Could not run the “GenerateResource” task because MSBuild could not create or connect to a task host with runtime “CLR2” and architecture “x86”. Please ensure that (1) the requested runtime and/or architecture are available on the machine, and (2) that the required executable “C:\Program Files (x86)\MSBuild\12.0\bin\MSBuildTaskHost.exe” exists and can be run.

To resolve it, go to your csproj file and add the following line under the default property group:

<PropertyGroup>

      <DisableOutOfProcTaskHost>true</DisableOutOfProcTaskHost>
</PropertyGroup>

And that should resolve the issue, everything should be compiled.