Search code examples
visual-studioasp.net-corekestrel-http-server

To which process should I attach Visual Studio Debugger to debug a Kestrel application?


I am bringing up command line and running my app using dotnet run command. This starts Kestrel and brings up my application.

How should I go with identify to which process to attach debugger so I can debug the website that Kestrel now hosts?

I specifically need to be able to do it this way - meaning I can't use standard F5.


Solution

  • Unfortunately, there is no way to tell right now using the tools provided by Visual Studio or .NET Core. Notice, though, that the community has already requested for this feature here, so you can voice your opinion there.

    Currently, the best option is to follow the steps to find out the id of the process given the application's port:

    1. Run netstat -abon | findStr "127.0.0.1:{PORTNUMBER}"
    2. Find the Id of the process returned above, and, for faster lookup, the name will be dotnet.exe

    If you feel adventurous, you may want to use something like this PowerShell, which will return directly the port number:

     $string = netstat -abon | findStr "127.0.0.1:{PORTNUMBER}"; $results = $string.split(' '); $results[$results.length - 1]