【问题标题】:VS 2019 C# console netcore 3 app not debuggingVS 2019 C# 控制台 net core 3 应用程序未调试
【发布时间】:2019-10-29 15:06:45
【问题描述】:

操作系统:Windows 10 企业版 10.0.18362

IDE:Visual Studio 2019 社区版 16.3.6 版

NET Core 版本:3.0.100 提交:04339c3a26

怎么做: 在 VS2019 中创建简单的 .NET Core 3 控制台应用,将目标平台切换到 x86 并按“F5”。

然后是 2 个选项:

  1. .NET Core 3 系统中安装的任何版本(x86、x64 的所有组合)。 x86 的环境变量“path”向上移动,“dotnet --info”显示它以 x86 版本为目标:

错误: The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core. The program '[18492] dotnet.exe' has exited with code -2147450751 (0x80008081).

附注在这种情况下,切换到 x64 目标平台时也会显示此错误。但以 AnyCPU 运行时一切正常。

  1. 已安装任何版本的 .NET Core,并删除了 x86 版本的环境变量或移至低于 x64 版本

错误: IDE 在 Program Files (x86) 中找不到 x86 版本的 dotnet.exe

dotnet x86 和 x64 版本的信息:

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x86
 Base Path:   C:\Program Files (x86)\dotnet\sdk\3.0.100\

Host (useful for support):
  Version: 3.0.0
  Commit:  7d57652f33

.NET Core SDKs installed:
  3.0.100 [C:\Program Files (x86)\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.0.0 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.0.0 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support):
  Version: 3.0.0
  Commit:  7d57652f33

.NET Core SDKs installed:
  2.1.509 [C:\Program Files\dotnet\sdk]
  2.2.103 [C:\Program Files\dotnet\sdk]
  3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

不得不说 x86 版本的编译控制台应用程序运行良好,如果你启动 exe 文件。只是无法在 VS 2019 的调试中启动它。如果切换到 AnyCPU/x64

【问题讨论】:

    标签: .net-core x86 visual-studio-2019


    【解决方案1】:

    我也在使用 Visual Studio 2019 (16.3.8) 并在尝试使用目标 x86(但 netcoreapp2.0 项目)进行调试时遇到类似错误:

    C:\Program Files\dotnet\dotnet.exe (process 40168) exited with code -532462766. 
    To automatically close the console when debugging stops, enable Tools->Options- 
    >Debugging->Automatically close the console when debugging stops.
    Press any key to close this window . . .
    

    如果我没记错的话,这在 Visual Studio 2017 中是开箱即用的,在安装 VS 2019 之后,VS 2017 也开始表现相同。 VS 无法检测到目标平台并相应地启动正确的 dotnet.exe,这很荒谬。

    幸运的是,修复很简单,将此设置添加到您的项目中:

    <PropertyGroup>
      <RunCommand Condition=" '$(Platform)' == 'x86' ">$(MSBuildProgramFiles32)\dotnet\dotnet</RunCommand>
    </PropertyGroup>
    

    所以在调试时,如果您当前的目标是 x86,它将使用 C:\Program Files (x86)\dotnet\dotnet.exe 而对于其他(默认设置)它将使用 C:\Program Files\dotnet\dotnet.exe

    当然你应该首先确保你有一个 .NET Core X86 SDK。

    更详细的设置(更多条件),见这里: https://github.com/dotnet/cli/issues/7532#issuecomment-330706524

    不过,上面的简单设置对于调试 x86 和 AnyCPU 都很有效。

    【讨论】:

    • 即使使用该设置,我也会遇到错误。我有 x86 SDK 和 Visual Studio 从 Program Files (x86) 运行 dotnet.ext,我的项目目标平台是 x86,我仍然有这个:C:\Program Files (x86)\dotnet\dotnet.exe(进程 52324)以代码 -2147450751 退出。 Debug 的输出是:目标进程退出而没有引发 CoreCLR 启动事件。确保目标进程配置为使用 .NET Core。如果目标进程未在 .NET Core 上运行,则可能会出现这种情况。程序“[52324] dotnet.exe”已退出,代码为 -2147450751 (0x80008081)。
    • 还有输出窗口中的调试日志,查看输出窗口中的测试日志。这显示了更多信息和解决方案的链接。
    猜你喜欢
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    • 2018-05-28
    • 2019-11-29
    • 2021-07-23
    • 1970-01-01
    相关资源
    最近更新 更多