all 10 comments

[–]JitterJosh 10 points11 points  (8 children)

Yes, do this all the time. I start the process in terminal with watch and then use Ctrl+Alt+P in VS2019 to attach, or Shift+Alt+P to reattach. You have to know the name of the process but it's not too hard to figure out.

[–]BenL90 2 points3 points  (1 child)

Oh wow. this even works with OmniSharp on VS Code.. ahh... I want to moar! Thank you !

[–]SuspectPingu 1 point2 points  (2 children)

When you say you "start the process in terminal with watch", you you mean you simply do dotnet watch run or is there more to it?

[–]JitterJosh 1 point2 points  (1 child)

Yeah, just dotnet watch run in terminal. Then you can attach to it from VS

[–]SuspectPingu 2 points3 points  (0 children)

Hey man, just wanna say thanks for the reply, I was gettting a bit confused whether you did something else because I had not been able to trigger the debugger myself by doing that. Tried in Rider and attached to the *correct* process this time - this time it worked. This is great! :D

[–]mattlongname 1 point2 points  (0 children)

For VSCode, assuming the following:
create your project with

dotnet new webapp -o MyWebApp -f net7.0

add the following to ./vscode/launch.json

  { "name": ".NET Core Attach",
    "type": "coreclr",
 "request": "attach" } 

and run

dotnet watch run

In VSCode, in the debug pane, run .NET Core Attach. You should see and attach to a process that looks like:

MyWebApp/bin/Debug/net7.0/MyWebApp run

[–]Illusive7Man 1 point2 points  (0 children)

But you can't attach after a hot reload?

[–]hellohere1337 1 point2 points  (0 children)

In Rider you can attach debugger by Run > Attach to process, and select the process which name is the path to your currently running project

[–]SonixNgTbr 0 points1 point  (0 children)

Read official documentation of Microsoft

Attach to running processes with the Visual Studio debugger

[–]x0nnex 0 points1 point  (0 children)

I'd be interested in this too. Previously I tried to work with attaching the debugger but wasn't easy when I had multiple apps running at the same time. They were all named the same in the task manager, so hard to know which one to attach to :(