如何从 .NET 核心 C# 项目中调试并进入本机代码项目?

How to debug and step into a native code project from inside a .NET core C# project?

我正在 VS2015 中开发 .NET 核心(.NET 标准 1.6)应用程序。应用程序通过 P/Invoke 调用 C++ 代码。现在我需要进入我的原生dll项目的C/C++代码。

在常规 .NET 应用程序中,通过在应用程序的 属性 window 中 启用非托管代码调试 ,我们可以进入 C/C++直接代码:

但我在 .NET 核心项目上找不到这样的选项。而且我知道我可以将调试器附加到应用程序以调试本机代码,但这不适合我的情况。

同样,我想从托管 C# 代码 调试到 本机 C/C++ 代码。

有什么想法吗?

也许我应该切换回 .NET Framework,以便调试本机代码。 printf确实很难调试。 :(

更新
已实现混合模式调试,即从托管 C# 代码调试到本机 C/C++ 代码。参见 Tutorial: Debug managed and native code in Visual Studio

更新
该功能可能已经实现,请参阅 this


正如@cynic所说,现在还不支持这个(2016-11-1)。

这可以通过 cynic 提供的以下步骤来验证。

  1. 在您的程序中暂停(例如 Console.ReadKey 调用)。
  2. 附加到 dotnet.exe 进程选择“托管 (CoreCLR)”和“本机”代码类型
  3. 您将收到一个消息框,明确指出“不支持互操作调试”。

这里a proper way调试原生dll

  1. Right click on the solution, Add Existing Project
  2. Open 'dotnet.exe'. This is normally installed to 'C:\Program Files\dotnet\dotnet.exe'.
  3. You should now see another node in solution explorer for dotnet.exe. Right click it to bring up project properties:
  4. Change the working directory to be what you want
  5. Change the arguments to be the path to your built dll
  6. Change the exe project to your startup project

RECOMENDED: Go to Tools->Options->Projects and Solutions->Build and Run, uncheck 'Only build startup projects and dependcies on Run'