Visual Studio 2019 编译.Net Core Console项目出现MSB4018 The "CreateAppHost" task failed unexpec(

Posted hand

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Visual Studio 2019 编译.Net Core Console项目出现MSB4018 The "CreateAppHost" task failed unexpec(相关的知识,希望对你有一定的参考价值。

需要测试一个小东东,使用Visual Studio 2019新建了一个.Net Core的Console程序,但是在编译的时候一直报错,死活编译不通过。

错误信息:

Severity Code Description Project File Line Suppression State
Error   MSB4018 The "CreateAppHost" task failed unexpectedly.
System.AggregateException: One or more errors occurred. ---> Microsoft.NET.HostModel.HResultException: 8007006E
   at Microsoft.NET.HostModel.ResourceUpdater.Update()
   at Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass2_0.<CreateAppHost>g__UpdateResources|1()
   at Microsoft.NET.HostModel.RetryUtil.RetryOnWin32Error(Action func)
   at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom)
   --- End of inner exception stack trace ---
   at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom)
   at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
---> (Inner Exception #0) Microsoft.NET.HostModel.HResultException: 8007006E
   at Microsoft.NET.HostModel.ResourceUpdater.Update()
   at Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass2_0.<CreateAppHost>g__UpdateResources|1()
   at Microsoft.NET.HostModel.RetryUtil.RetryOnWin32Error(Action func)
   at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom)<---

---> (Inner Exception #1) System.UnauthorizedAccessException: Access to the path 'D:VS2019CodeProjectsConsoleApp9ConsoleApp9objDebug
etcoreapp3.1ConsoleApp9.exe' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalDelete(String path, Boolean checkHost)
   at System.IO.File.Delete(String path)
   at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom)<---
    ConsoleApp9 C:Program Filesdotnetsdk3.1.100SdksMicrosoft.NET.Sdk	argetsMicrosoft.NET.Sdk.targets    393 

网上的方案有如下,也都进行了尝试:

  • 重启Visual Studio
  • 以管理员身份运行Visual Studio
  • 清理解决方案
  • 删除bin目录下的所有文件

然鹅,均无效,无奈之下继续寻找解决方案,发现用Process Monitor来监控到底是谁在搞鬼。

点击下载 Process Monitor.

终于发现了罪魁祸首。

技术图片

原来是你,让我花了我一个上午的时间在折腾。

立马干掉

技术图片

果然,一切编译正常,大功告成。

以上是关于Visual Studio 2019 编译.Net Core Console项目出现MSB4018 The "CreateAppHost" task failed unexpec(的主要内容,如果未能解决你的问题,请参考以下文章

Visual Studio 2019 编译.Net Core Console项目出现MSB4018 The "CreateAppHost" task failed unexpec(

如何在 Visual Studio 2019 中启用编译器警告?

Visual Studio 2019 MVC 项目模板无法编译

允许此预编译站点可更新 Visual Studio 2019

Visual Studio 2019 未显示 .NET 5 框架

使用 CMake 和 Visual Studio 2019 编译 GLEW?