Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 323
nikib3ro Avatar asked Jun 11 '18 22:06

nikib3ro


People also ask

How do you attach a debugger to a process in Visual Studio?

You can attach the Visual Studio debugger to a running process on a local or remote computer. After the process is running, select Debug > Attach to Process or press Ctrl+Alt+p in Visual Studio, and use the Attach to Process dialog to attach the debugger to the process.

What does it mean to attach a debugger?

That means to attach a debugger (i.e visual studio's integrated debugger) to the process so you can pause it and inspect variables at runtime. This happens when you hit F5 automatically, or can be done manually using the debug menu.

How do I insert a w3wp process in Visual Studio?

Open Visual Studio in Administrator Mode, then Debug -> attach to process -> tick the check box "Show processes from all user", select w3wp.exe.


Video Answer


2 Answers

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]
like image 93
Camilo Terevinto Avatar answered Sep 20 '22 03:09

Camilo Terevinto


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}");
like image 33
Ruben Bartelink Avatar answered Sep 21 '22 03:09

Ruben Bartelink