0

Here is what I am trying to do... I have two separate Visual Studio solutions open, they are completely separate solutions, and I want it to remain that way. Solution 1 is what my powershell DTEObject is pointing to. I want to be able to switch to Solution 2, and open a file in that session. Here is the powershell code I am using to get the DTE object and executing the open file command:

$dteobj = [runtime.interopservices.marshal]::getactiveobject('VisualStudio.DTE')
$dteobj.ExecuteCommand("Open ""$file""")
$dteobj.ExecuteCommand("Edit.Goto $line")

The reason why I want to switch solutions is because I want to then bring focus to the window of the solution that contains that file so that it doesn't confuse people about what files are in what solutions. Hopefully that makes enough sense.

HeedfulCrayon
  • 837
  • 6
  • 20
  • In order to do this, you need to delve down into the running object table. Here starts the rabbit hole for ye https://stackoverflow.com/questions/11835617/understanding-the-running-object-table don't take any pills while underground. –  Nov 15 '17 at 19:10

1 Answers1

0

I figured it out. You can use the powershell command Get-RunningObject from the PSCX module, and you have to select that object's DTE

$dteObj = Get-RunningObject | Where-Object {$_.FullName -eq "$solutionDir$solutionName"} | Select-Object DTE
$dteobj.DTE.ExecuteCommand("Open ""$file""")
$dteobj.DTE.ExecuteCommand("Edit.Goto $line")
HeedfulCrayon
  • 837
  • 6
  • 20
  • You might want to add some details that the `Get-RunningObject` command comes from the open source PSCX module, and is not built in. – x0n Nov 20 '17 at 20:11
  • 1
    Oh, lol I didn't even know that. I know I have that module though. I have edited my answer to include that info – HeedfulCrayon Nov 21 '17 at 15:55
  • 1
    Powershell 5.1, no modules to install. same idea though. https://github.com/jefflomax/visual-studio-dte-utilities/blob/main/getDteBySolutionName.ps1 – AUSTX_RJL Feb 06 '22 at 04:17