7

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.

nikib3ro
  • 19,427
  • 21
  • 113
  • 173

3 Answers3

7

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]
Camilo Terevinto
  • 26,697
  • 6
  • 67
  • 99
2

You can 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}");
S.Serpooshan
  • 6,368
  • 2
  • 29
  • 53
Ruben Bartelink
  • 55,135
  • 22
  • 172
  • 222
  • 1
    @kape123 Not my idea but happy to share it - (I was annoyed by the fact the other answer didnt work for me immediately and posted this to help others). Other suggestion is that newest processes are top of list so that's the one to attach to (I guess that translates to some powershell command someone will post \/ imminently :D) – Ruben Bartelink Dec 09 '18 at 23:29
  • 1
    This really helps. Also, if you are using 2017, if you filter the list on "dotnet" and sort on id, the highest one, the first one in the list, is probably the one you want. – Marnee KG7SIO Apr 07 '19 at 23:24
1

Older question, but here's how we are working around it.

From a clean start, using $ dotnet run will create a single instance of Kestrel, so it's easy to attach to from Visual Studio.

However, running$ dotnet build && dotnet run will create an instance of the build server AND an instance of Kestrel. Now it's harder to know what dotnet process to attach to. Further, running this command multiple times can create additional processes.

Our solution was to use $ dotnet build && dotnet build-server shutdown && dotnet run. This stops the build server after the build, so now there's only one dotnet process to attach to.

There might be additional solutions at some point here: https://github.com/dotnet/cli/issues/9481

Lavamantis
  • 3,155
  • 1
  • 22
  • 20