Unable to debug project within solution when it is not the startup project

1k Views Asked by At

I have an application that has a startup project (ProjectA) that runs another executable in another Project (ProjectB). When I start the solution with ProjectA as the startup project, I am unable to debug ProjectB. It is unable to load the PDB file even though it is in the directory where its searching.

However, when I start the application and ProjectB is the startup project, I am able to debug it. I assume this is because it is referencing the executable instead of the dll.

Why is this so? How do I get around this so that I can have ProjectA be the startup project and still debug ProjectB?

1

There are 1 best solutions below

0
IV. On

As I understand it, your Project A has started the Project B .exe. Something along these lines:

Public Class ProjectAForm
    Private Sub ButtonRunProjectB_Click(sender As Object, e As EventArgs) Handles ButtonRunProjectB.Click
        Process.Start("D:\Github\stackoverflow\multi-project-debugging\project-b\bin\Debug\netcoreapp3.1\project-b.exe")
    End Sub
End Class

You want to debug Project B in this context, but your debugger is attached only to Project A and not to Project B:

not attached


Manual

The interactive way to go about it is with DEBUG\Attach to Process...

attach to process

Now you will hit your breakpoints.

attached


Programmatic

Doing this automatically is tricky but possible. Refer to this answer:

Can I programmatically attach a running .NET 6 process to a running instance of Visual Studio debugger?


Suggestion

If Project A doesn't reference Project B directly (that is, they're completely independent inside a common solution where Project A is the startup) I find that it saves a lot of confusion to have Project B build automatically (if needed) whenever Project A runs. Manually setting project-a to depend on project-b achieves this outcome.

project dependencies