5

My project has both client and server components in the same solution file. I usually have the debugger set to start them together when debugging, but it's often the case where I start the server up outside of the debugger so I can start and stop the client as needed when working on client-side only stuff. (this is much faster).

I'm trying to save myself the hassle of poking around in Solution Explorer to start individual projects and would rather just stick a button on the toolbar that calls a macro that starts the debugger for individual projects (while leaving "F5" type debugging alone to start up both processess).

I tried recording, but that didn't really result in anything useful.

So far all I've managed to do is to locate the project item in the solution explorer:

 Dim projItem As UIHierarchyItem

 projItem = DTE.ToolWindows.SolutionExplorer.GetItem("SolutionName\ProjectFolder\ProjectName").Select(vsUISelectionType.vsUISelectionTypeSelect)

(This is based loosely on how the macro recorder tried to do it. I'm not sure if navigating the UI object model is the correct approach, or if I should be looking at going through the Solution/Project object model instead).

Jason Diller
  • 3,360
  • 2
  • 24
  • 25

2 Answers2

6

Ok. This appears to work from most UI (all?) contexts provided the solution is loaded:

 Sub DebugTheServer()
    DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
    DTE.ActiveWindow.Object.GetItem("Solution\ServerFolder\ServerProject").Select(vsUISelectionType.vsUISelectionTypeSelect)
    DTE.Windows.Item(Constants.vsWindowKindOutput).Activate()
    DTE.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Debug.Startnewinstance")
 End Sub
Jason Diller
  • 3,360
  • 2
  • 24
  • 25
0

From a C# add-in, the following worked for me:

Dte.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate();
Dte.ToolWindows.SolutionExplorer.GetItem("SolutionName\\SolutionFolderName\\ProjectName").Select(vsUISelectionType.vsUISelectionTypeSelect);
Erwin Mayer
  • 18,076
  • 9
  • 88
  • 126
  • I am saying that it should work from any Visual Studio Add-in. – Erwin Mayer Jan 29 '16 at 07:06
  • May be i' missing some references apart from EnvDtE amd EnvDte80. Yes? – vendettamit Jan 29 '16 at 12:40
  • No it is a bit more complicated than that to get the DTE object if your project is not a VS Add in. Not sure what your question is but you should probably open a new one rather than commenting on this answer. – Erwin Mayer Jan 29 '16 at 14:15
  • 1
    I see you already found my gist here: https://gist.github.com/mayerwin/82301024371e9c555d24 it should help you achieve what you need. – Erwin Mayer Jan 29 '16 at 14:49
  • Yes.. but that wasn't working with .Net 4.5 due to missing namespaces and classes. I found another solution on [SO here](http://stackoverflow.com/questions/11811856/attach-debugger-in-c-sharp-to-another-process/11811881) for 4.5. – vendettamit Jan 29 '16 at 15:21