问题描述
在 Visual Studio 2022 中调试(由 .NET 5 升级到 .NET 6 的)控制台项目时,如果在项目中配置了生成单文件
<PublishSingleFile>true</PublishSingleFile>
生成并调试后会弹出
无法附加到 CoreCLR。不支持操作。未知错误 0x80004005。
Unable to attach to CoreCLR. Operation not supported. Unknown error: 0x80004005.
的对话框,如下图
解决方法
相关 issue
- https://github.com/dotnet/runtime/issues/45382
- https://developercommunity2.visualstudio.com/t/Unable-to-attach-to-CoreCLR-when-debug/1523427?entry=problem&ref=native&refTime=1636746090780&refUserId=8c25c91a-2d4f-6773-b0fa-d18fdec3f989
在项目配置文件中,给生成单文件添加一个条件,限制其只在指定配置下生成单文件
<PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile> <!-- or --> <PropertyGroup Condition="'$(Configuration)' == 'Release'"> <PublishSingleFile>true</PublishSingleFile> </PropertyGroup>