Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not run the "GenerateResource" task because MSBuild could not create or connect to a task host with runtime "CLR4" and architecture "x64"

I am using Visual Studio 2017 Enterprise version 15.7.1 and .NET Framework 4.5.

I just installed Windows 10 Update version 10.0.18363 build 18363.

I can build other projects in the same Solution, but for this one project, I am getting this error while building

2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(3045,5): 
error MSB4216: 
Could not run the "GenerateResource" task because MSBuild could not create or connect to a task host with runtime "CLR4" and architecture "x64".  
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)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64\MSBuild.exe" exists and can be run.

Error   MSB4028 The "GenerateResource" task's outputs could not be retrieved from the "FilesWritten" parameter. 
Object does not match target type.  my-project-name C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets   3066

How can I fix this ? Thank you.

like image 943
faujong Avatar asked Oct 10 '20 15:10

faujong


2 Answers

Try these:

1) add these xml node in your xxx.csproj file:

<PropertyGroup> 

<GenerateResourceMSBuildArchitecture>CurrentArchitecture</GenerateResourceMSBuildArchitecture>
<GenerateResourceMSBuildRuntime>CurrentRuntime</GenerateResourceMSBuildRuntime>
    
</PropertyGroup>

2) add a system environment variable called DisableOutOfProcTaskHost and set its value to true.

Or set DISABLEOUTOFPROCTASKHOST to 1.

3) since your VS2017 is too old, I suggest you could update your VS2017 to the latest version in case there are some fixes. Or repair vs.

Also, make sure that you have installed the workload .Net Core cross-platform development in vs installer.

enter image description here

4) close VS, delete .vs hidden folder under solution folder, bin and obj folder then restart your VS to test again. Besides, you can change your target framework version to net framework 4.6.1 and Configuration to Any CPU.

like image 110
Mr Qian Avatar answered Sep 18 '22 01:09

Mr Qian


I had the same Error (in version 16.9.3) but By Repairing Visual Studio 2019, Updating last version of windows 10, close VS, delete .vs hidden folder (under solution folder) ,bin and obj folder then restart your VS . Fortunately My problem was solved.

like image 41
aseman arabsorkhi Avatar answered Sep 21 '22 01:09

aseman arabsorkhi