【发布时间】:2018-06-11 22:12:36
【问题描述】:
我正在使用dotnet run 命令启动命令行并运行我的应用程序。这会启动 Kestrel 并调出我的应用程序。
我应该如何确定要将调试器附加到哪个进程,以便调试 Kestrel 现在托管的网站?
我特别需要能够这样做 - 这意味着我不能使用标准 F5。
【问题讨论】:
标签: visual-studio asp.net-core kestrel-http-server
我正在使用dotnet run 命令启动命令行并运行我的应用程序。这会启动 Kestrel 并调出我的应用程序。
我应该如何确定要将调试器附加到哪个进程,以便调试 Kestrel 现在托管的网站?
我特别需要能够这样做 - 这意味着我不能使用标准 F5。
【问题讨论】:
标签: visual-studio asp.net-core kestrel-http-server
较早的问题,但这是我们正在解决的问题。
从头开始,使用 $ dotnet run 将创建 Kestrel 的单个实例,因此很容易从 Visual Studio 附加到。
但是,running$ dotnet build && dotnet run 将创建一个构建服务器实例和一个 Kestrel 实例。现在很难知道要附加到哪个dotnet 进程。此外,多次运行此命令可能会创建额外的进程。
我们的解决方案是使用$ dotnet build && dotnet build-server shutdown && dotnet run。这会在构建之后停止构建服务器,因此现在只有一个 dotnet 进程可以附加到。
这里可能会有其他解决方案:https://github.com/dotnet/cli/issues/9481
【讨论】:
不幸的是,目前无法使用 Visual Studio 或 .NET Core 提供的工具来判断。但请注意,社区已经请求此功能 here,因此您可以在那里发表您的意见。
目前,最好的选择是按照步骤to find out the id of the process given the application's port:
netstat -abon | findStr "127.0.0.1:{PORTNUMBER}"
dotnet.exe 如果你喜欢冒险,你可能想要使用类似这个 PowerShell 的东西,它会直接返回端口号:
$string = netstat -abon | findStr "127.0.0.1:{PORTNUMBER}"; $results = $string.split(' '); $results[$results.length - 1]
【讨论】:
你可以print the pid to the console and use that to select from Ctrl-Alt-P
Console.WriteLine($"Running at pid {System.Diagnostics.Process.GetCurrentProcess().Id}");
【讨论】: