无法运行“ GenerateResource”任务,因为MSBuild无法使用运行时“ CLR4”和体系结构“ x64”创建或连接到任务主机

问题描述

我正在使用Visual Studio 2017企业版15.7.1和.NET Framework 4.5。

我刚刚安装了Windows 10更新版本10.0.18363版本18363。

我可以在同一解决方案中构建其​​他项目,但是对于这个项目,在构建时出现此错误

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

我该如何解决? 谢谢。

解决方法

尝试以下方法:

1)将这些xml节点添加到您的xxx.csproj文件中:

<PropertyGroup> 

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

2)添加一个名为DisableOutOfProcTaskHost的系统环境变量,并将其值设置为true

DISABLEOUTOFPROCTASKHOST设置为1

3),因为您的 VS2017 太旧了,建议您将 VS2017 更新到最新版本,以防出现某些问题。 。或repair vs

,请确保已在vs安装程序中安装了 .Net Core跨平台开发工作负载。

enter image description here

4)关闭VS,删除解决方案文件夹.vsbin文件夹下的obj隐藏文件夹,然后重新启动VS以再次进行测试。 此外,您可以将目标框架版本更改为net framework 4.6.1,将配置更改为Any CPU

,

我遇到了同样的错误(版本 16.9.3),但是通过修复 Visual Studio 2019、更新最新版本的 Windows 10、关闭 VS、删除 .vs 隐藏文件夹(在解决方案文件夹下)、bin 和 obj 文件夹然后重新启动你的VS 。幸运的是我的问题解决了。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...