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.

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

3 Comments

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."
Found it myself. You just need to prepend your command with an ampersand (&) sign and it will work.
Any idea on how to silently ignore errors files that do not exist or are not part of the visual studio solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.