VS 2019 C#控制台netcore 3应用未调试

时间:2019-10-29 15:06:45

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

操作系统:Windows 10 Enterprise 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的环境变量“路径”上移,“ 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).

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

  1. 已安装任何版本的.NET Core,并且已删除x86版本的环境变量,并将其移至x64版本以下

错误::IDE在程序文件(x86)中找不到dotnet.exe的x86版本

x86和x64版本的dotnet的信息:

.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]

不得不说,如果您启动exe文件,则x86版本的已编译控制台应用程序会很好地工作。只是无法在VS 2019的调试中启动它。如果切换到AnyCPU / x64

1 个答案:

答案 0 :(得分:0)

我也在使用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。