如何在 Visual Studio 2019 中调试引用 .NET Framework 4.8 class 库的 .NET 5 WinForms 应用程序

Howto debug .NET 5 WinForms application that references .NET Framework 4.8 class library in Visual Studio 2019

我测试了引用 .NET Framework 4.8 class 库的 .NET 5 WinForms 应用程序 - Github link.

我想这是可能的,因为 .NET Framework compatibility mode

当我尝试在 Visual Studio 2019 16.8.4 中调试 class 库时(通过启动我的 .NET 5 应用程序)我得到一个错误:

The debugger was configured to use the Desktop CLR (.NET Framework) Managed debugger, but the target process loaded the CoreCLR (.NET Core) runtime. The debugger was configured to use the Desktop CLR (.NETFramework) Managed debugger, but the target process loaded the CoreCLR (.Net Core) runtime. To debug this project, configure it to use the 'Managed (CoreCLR)' debugger.

我在哪里可以找到一个选项 来使用 'Managed (CoreCLR)' 调试器

提前致谢。

更新 如果我从 .NET 5 应用程序项目开始调试 - 我可以进入 .NET Framework 4.8 class 库。但我想从 class 库项目进行调试。

一个有用的功能是将您的网络框架项目从 non-sdk 更改为 new-sdk csproj 格式。

1)创建一个net core class库工程然后进入其csproj文件然后将targetframework改成:

<TargetFramework>net48</TargetFramework>

所以 你得到了一个 net framework4.8CoreCLR.

兼容的项目

参见 this document

完成后,请将非sdk net framework4.8文件移动到新文件中。

2) 使用 Attach to Process 它应该有一个执行程序来 运行 lib 项目的代码.

您可以check this issue获取详细步骤,当您打开Attach to Process并记得选择Managed(.Net Core,NET5+ ) 那就是调试器。

这是a similar issue about it

其实,推荐方案一,方案二可能会有一些小问题