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新建了一个.Net Core的Console程序,但是在编译的时候一直报错,死活编译不通过。
错误信息:

Severity Code Description Project File Line Suppression State ErrorMSB4018 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.targets393

网上的方案有如下,也都进行了尝试:
  • 重启Visual Studio
  • 以管理员身份运行Visual Studio
  • 清理解决方案
  • 删除bin目录下的所有文件
【Visual Studio 2019 编译.Net Core Console项目出现MSB4018 The " CreateAppHost" task failed unexpec(】然鹅,均无效,无奈之下继续寻找解决方案,发现用Process Monitor来监控到底是谁在搞鬼。
点击下载 Process Monitor.
终于发现了罪魁祸首。
Visual Studio 2019 编译.Net Core Console项目出现MSB4018 The &quot;CreateAppHost&quot; task failed unexpec(

文章图片

原来是你,让我花了我一个上午的时间在折腾。
立马干掉
Visual Studio 2019 编译.Net Core Console项目出现MSB4018 The &quot;CreateAppHost&quot; task failed unexpec(

文章图片

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

    推荐阅读