2

Is there a command to open a project item (such as a class file) from Package Manager Console (a.k.a. PowerShell) within Visual Studio? That is the same thing that would happen when I double-click the file in Solution Explorer.

I tried using Invoke-Item but that happens to open a new instance of Visual Studio.

dotNET
  • 31,005
  • 20
  • 138
  • 226

1 Answers1

4
$DTE.ExecuteCommand(“File.OpenFile”, "a path to your file")

You can refer to a local project file this way:

$path = [System.IO.Path]
$file = $path::Combine($path::GetDirectoryName($project.FileName), “your local path”)
$DTE.ExecuteCommand(“File.OpenFile”, $file)
David Brabant
  • 39,073
  • 16
  • 82
  • 103
  • Works like a charm. Thanks a ton! – dotNET Feb 10 '15 at 08:02
  • How can I pipe it? I appended it to the end of my command, but it says "Expressions are only allowed as the first element of a pipeline." – dotNET Feb 10 '15 at 08:05
  • Found it myself. You just need to prepend your command with an ampersand (`&`) sign and it will work. – dotNET Feb 10 '15 at 08:40
  • Any idea on how to silently ignore errors files that do not exist or are not part of the visual studio solution? – MoMo Oct 17 '17 at 19:42